Bug 1552979 - Make JS::CompileModule return the module directly, rather than by outparam duplicative of a boolean return value. r=arai
authorJeff Walden <jwalden@mit.edu>
Tue, 21 May 2019 10:21:56 -0700
changeset 475407 d22bd25523e5a8a49030ae35e9a5aba797c466a3
parent 475406 6fac68354ef48e8945ccf506a5602aadddd5a3b9
child 475408 d31060048c955584fbf1eb34648239641547060e
push id36061
push usercbrindusan@mozilla.com
push dateFri, 24 May 2019 21:49:59 +0000
treeherdermozilla-central@5d3e1ea77693 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1552979
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1552979 - Make JS::CompileModule return the module directly, rather than by outparam duplicative of a boolean return value. r=arai
dom/base/nsJSUtils.cpp
dom/script/ScriptLoader.cpp
js/public/Modules.h
js/src/vm/Modules.cpp
--- a/dom/base/nsJSUtils.cpp
+++ b/dom/base/nsJSUtils.cpp
@@ -460,20 +460,22 @@ nsresult nsJSUtils::CompileModule(JSCont
   MOZ_ASSERT(JS_IsGlobalObject(aEvaluationGlobal));
   MOZ_ASSERT(JS::CurrentGlobalOrNull(aCx) == aEvaluationGlobal);
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(CycleCollectedJSContext::Get() &&
              CycleCollectedJSContext::Get()->MicroTaskLevel());
 
   NS_ENSURE_TRUE(xpc::Scriptability::Get(aEvaluationGlobal).Allowed(), NS_OK);
 
-  if (!JS::CompileModule(aCx, aCompileOptions, aSrcBuf, aModule)) {
+  JSObject* module = JS::CompileModule(aCx, aCompileOptions, aSrcBuf);
+  if (!module) {
     return NS_ERROR_FAILURE;
   }
 
+  aModule.set(module);
   return NS_OK;
 }
 
 nsresult nsJSUtils::InitModuleSourceElement(JSContext* aCx,
                                             JS::Handle<JSObject*> aModule,
                                             nsIScriptElement* aElement) {
   JS::Rooted<JS::Value> value(aCx);
   nsresult rv = nsContentUtils::WrapNative(aCx, aElement, &value,
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -11,17 +11,17 @@
 #include "LoadedScript.h"
 #include "ModuleLoadRequest.h"
 
 #include "prsystem.h"
 #include "jsapi.h"
 #include "jsfriendapi.h"
 #include "js/CompilationAndEvaluation.h"
 #include "js/MemoryFunctions.h"
-#include "js/Modules.h"  // JS::CompileModule, JS::FinishDynamicModuleImport, JS::{G,S}etModuleResolveHook, JS::Get{ModulePrivate,ModuleScript,RequestedModule{s,Specifier,SourcePos}}, JS::SetModule{DynamicImport,Metadata}Hook
+#include "js/Modules.h"  // JS::FinishDynamicModuleImport, JS::{G,S}etModuleResolveHook, JS::Get{ModulePrivate,ModuleScript,RequestedModule{s,Specifier,SourcePos}}, JS::SetModule{DynamicImport,Metadata}Hook
 #include "js/OffThreadScriptCompilation.h"
 #include "js/Realm.h"
 #include "js/SourceText.h"
 #include "js/Utility.h"
 #include "xpcpublic.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIContent.h"
 #include "nsJSUtils.h"
--- a/js/public/Modules.h
+++ b/js/public/Modules.h
@@ -82,20 +82,19 @@ extern JS_PUBLIC_API void SetModuleDynam
 extern JS_PUBLIC_API bool FinishDynamicModuleImport(
     JSContext* cx, Handle<Value> referencingPrivate,
     Handle<JSString*> specifier, Handle<JSObject*> promise);
 
 /**
  * Parse the given source buffer as a module in the scope of the current global
  * of cx and return a source text module record.
  */
-extern JS_PUBLIC_API bool CompileModule(JSContext* cx,
-                                        const ReadOnlyCompileOptions& options,
-                                        SourceText<char16_t>& srcBuf,
-                                        MutableHandle<JSObject*> moduleRecord);
+extern JS_PUBLIC_API JSObject* CompileModule(
+    JSContext* cx, const ReadOnlyCompileOptions& options,
+    SourceText<char16_t>& srcBuf);
 
 /**
  * Set a private value associated with a source text module record.
  */
 extern JS_PUBLIC_API void SetModulePrivate(JSObject* module,
                                            const Value& value);
 
 /**
--- a/js/src/vm/Modules.cpp
+++ b/js/src/vm/Modules.cpp
@@ -75,26 +75,24 @@ JS_PUBLIC_API bool JS::FinishDynamicModu
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
   cx->check(referencingPrivate, promise);
 
   return js::FinishDynamicModuleImport(cx, referencingPrivate, specifier,
                                        promise);
 }
 
-JS_PUBLIC_API bool JS::CompileModule(JSContext* cx,
-                                     const ReadOnlyCompileOptions& options,
-                                     SourceText<char16_t>& srcBuf,
-                                     MutableHandle<JSObject*> module) {
+JS_PUBLIC_API JSObject* JS::CompileModule(JSContext* cx,
+                                          const ReadOnlyCompileOptions& options,
+                                          SourceText<char16_t>& srcBuf) {
   MOZ_ASSERT(!cx->zone()->isAtomsZone());
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
 
-  module.set(js::frontend::CompileModule(cx, options, srcBuf));
-  return !!module;
+  return js::frontend::CompileModule(cx, options, srcBuf);
 }
 
 JS_PUBLIC_API void JS::SetModulePrivate(JSObject* module, const Value& value) {
   JSRuntime* rt = module->zone()->runtimeFromMainThread();
   module->as<ModuleObject>().scriptSourceObject()->setPrivate(rt, value);
 }
 
 JS_PUBLIC_API JS::Value JS::GetModulePrivate(JSObject* module) {