Title: [213817] releases/WebKitGTK/webkit-2.16
Revision
213817
Author
[email protected]
Date
2017-03-13 03:48:13 -0700 (Mon, 13 Mar 2017)

Log Message

Merge r213452 - Null pointer crash when loading module with unresolved import also as a script file
https://bugs.webkit.org/show_bug.cgi?id=168971

Reviewed by Saam Barati.

JSTests:

* stress/re-execute-error-module.js: Added.
(shouldBe):
(async):
* stress/resources/error-module.js: Added.

Source/_javascript_Core:

If linking throws an error, this error should be re-thrown
when requesting the same module.

* builtins/ModuleLoaderPrototype.js:
(globalPrivate.newRegistryEntry):
* runtime/JSModuleRecord.cpp:
(JSC::JSModuleRecord::link):

Modified Paths

Added Paths

Diff

Modified: releases/WebKitGTK/webkit-2.16/JSTests/ChangeLog (213816 => 213817)


--- releases/WebKitGTK/webkit-2.16/JSTests/ChangeLog	2017-03-13 10:45:57 UTC (rev 213816)
+++ releases/WebKitGTK/webkit-2.16/JSTests/ChangeLog	2017-03-13 10:48:13 UTC (rev 213817)
@@ -1,3 +1,15 @@
+2017-03-06  Yusuke Suzuki  <[email protected]>
+
+        Null pointer crash when loading module with unresolved import also as a script file
+        https://bugs.webkit.org/show_bug.cgi?id=168971
+
+        Reviewed by Saam Barati.
+
+        * stress/re-execute-error-module.js: Added.
+        (shouldBe):
+        (async):
+        * stress/resources/error-module.js: Added.
+
 2017-02-28  Oleksandr Skachkov  <[email protected]>
 
         Use of arguments in arrow function is slow

Added: releases/WebKitGTK/webkit-2.16/JSTests/stress/re-execute-error-module.js (0 => 213817)


--- releases/WebKitGTK/webkit-2.16/JSTests/stress/re-execute-error-module.js	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.16/JSTests/stress/re-execute-error-module.js	2017-03-13 10:48:13 UTC (rev 213817)
@@ -0,0 +1,26 @@
+function shouldBe(actual, expected)
+{
+    if (actual !== expected)
+        throw new Error(`bad value: ${String(actual)}`);
+}
+
+(async function () {
+    {
+        let errorMessage = null;
+        try {
+            await import("./resources/error-module.js");
+        } catch (error) {
+            errorMessage = String(error);
+        }
+        shouldBe(errorMessage, `SyntaxError: Importing binding name 'x' is not found.`);
+    }
+    {
+        let errorMessage = null;
+        try {
+            await import("./resources/error-module.js");
+        } catch (error) {
+            errorMessage = String(error);
+        }
+        shouldBe(errorMessage, `SyntaxError: Importing binding name 'x' is not found.`);
+    }
+}()).catch(abort);

Added: releases/WebKitGTK/webkit-2.16/JSTests/stress/resources/error-module.js (0 => 213817)


--- releases/WebKitGTK/webkit-2.16/JSTests/stress/resources/error-module.js	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.16/JSTests/stress/resources/error-module.js	2017-03-13 10:48:13 UTC (rev 213817)
@@ -0,0 +1 @@
+import {x} from "./error-module.js"

Modified: releases/WebKitGTK/webkit-2.16/Source/_javascript_Core/ChangeLog (213816 => 213817)


--- releases/WebKitGTK/webkit-2.16/Source/_javascript_Core/ChangeLog	2017-03-13 10:45:57 UTC (rev 213816)
+++ releases/WebKitGTK/webkit-2.16/Source/_javascript_Core/ChangeLog	2017-03-13 10:48:13 UTC (rev 213817)
@@ -1,3 +1,18 @@
+2017-03-06  Yusuke Suzuki  <[email protected]>
+
+        Null pointer crash when loading module with unresolved import also as a script file
+        https://bugs.webkit.org/show_bug.cgi?id=168971
+
+        Reviewed by Saam Barati.
+
+        If linking throws an error, this error should be re-thrown
+        when requesting the same module.
+
+        * builtins/ModuleLoaderPrototype.js:
+        (globalPrivate.newRegistryEntry):
+        * runtime/JSModuleRecord.cpp:
+        (JSC::JSModuleRecord::link):
+
 2017-03-06  Daniel Ehrenberg  <[email protected]>
 
         Currency digits calculation in Intl.NumberFormat should call out to ICU

Modified: releases/WebKitGTK/webkit-2.16/Source/_javascript_Core/builtins/ModuleLoaderPrototype.js (213816 => 213817)


--- releases/WebKitGTK/webkit-2.16/Source/_javascript_Core/builtins/ModuleLoaderPrototype.js	2017-03-13 10:45:57 UTC (rev 213816)
+++ releases/WebKitGTK/webkit-2.16/Source/_javascript_Core/builtins/ModuleLoaderPrototype.js	2017-03-13 10:48:13 UTC (rev 213817)
@@ -92,7 +92,6 @@
     return {
         key: key,
         state: @ModuleFetch,
-        metadata: @undefined,
         fetch: @undefined,
         instantiate: @undefined,
         satisfy: @undefined,
@@ -99,7 +98,8 @@
         dependencies: [], // To keep the module order, we store the module keys in the array.
         dependenciesMap: @undefined,
         module: @undefined, // JSModuleRecord
-        error: @undefined,
+        linkError: @undefined,
+        linkSucceeded: true,
     };
 }
 
@@ -350,24 +350,28 @@
 
     "use strict";
 
-    // FIXME: Current implementation does not support optionalInstance.
-    // So Link's step 3 is skipped.
-    // https://bugs.webkit.org/show_bug.cgi?id=148171
-
+    if (!entry.linkSucceeded)
+        throw entry.linkError;
     if (entry.state === @ModuleReady)
         return;
     @setStateToMax(entry, @ModuleReady);
 
-    // Since we already have the "dependencies" field,
-    // we can call moduleDeclarationInstantiation with the correct order
-    // without constructing the dependency graph by calling dependencyGraph.
-    var dependencies = entry.dependencies;
-    for (var i = 0, length = dependencies.length; i < length; ++i) {
-        var pair = dependencies[i];
-        this.link(pair.value.registryEntry, fetcher);
+    try {
+        // Since we already have the "dependencies" field,
+        // we can call moduleDeclarationInstantiation with the correct order
+        // without constructing the dependency graph by calling dependencyGraph.
+        var dependencies = entry.dependencies;
+        for (var i = 0, length = dependencies.length; i < length; ++i) {
+            var pair = dependencies[i];
+            this.link(pair.value.registryEntry, fetcher);
+        }
+
+        this.moduleDeclarationInstantiation(entry.module, fetcher);
+    } catch (error) {
+        entry.linkSucceeded = false;
+        entry.linkError = error;
+        throw error;
     }
-
-    this.moduleDeclarationInstantiation(entry.module, fetcher);
 }
 
 // Module semantics.

Modified: releases/WebKitGTK/webkit-2.16/Source/_javascript_Core/runtime/JSModuleRecord.cpp (213816 => 213817)


--- releases/WebKitGTK/webkit-2.16/Source/_javascript_Core/runtime/JSModuleRecord.cpp	2017-03-13 10:45:57 UTC (rev 213816)
+++ releases/WebKitGTK/webkit-2.16/Source/_javascript_Core/runtime/JSModuleRecord.cpp	2017-03-13 10:48:13 UTC (rev 213817)
@@ -86,8 +86,9 @@
         throwSyntaxError(exec, scope);
         return;
     }
+    instantiateDeclarations(exec, executable);
+    RETURN_IF_EXCEPTION(scope, void());
     m_moduleProgramExecutable.set(vm, this, executable);
-    instantiateDeclarations(exec, executable);
 }
 
 void JSModuleRecord::instantiateDeclarations(ExecState* exec, ModuleProgramExecutable* moduleProgramExecutable)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to