[JSC] Remove loadModule function in jsc.cpp
authoryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Sep 2018 20:51:22 +0000 (20:51 +0000)
committeryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Sep 2018 20:51:22 +0000 (20:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184808

Patch by Yusuke Suzuki <utatane.tea@gmail.com> on 2018-09-08
Reviewed by Darin Adler.

JSTests:

Use `import` expression instead.

* modules/different-view.js:
(from.string_appeared_here.shouldThrow): Deleted.
* modules/fallback-ambiguous.js:
(from.string_appeared_here.shouldThrow): Deleted.
* modules/import-error.js:
(from.string_appeared_here.shouldThrow): Deleted.
(shouldThrow): Deleted.
* modules/indirect-export-error.js:
(from.string_appeared_here.shouldThrow): Deleted.
(shouldThrow): Deleted.
* modules/namespace-error.js:
(from.string_appeared_here.shouldThrow): Deleted.

Source/JavaScriptCore:

Since we have `import`, we do not need to have `loadModule` function for testing purpose.

* jsc.cpp:
(GlobalObject::finishCreation):
(functionLoadModule): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235831 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JSTests/ChangeLog
JSTests/modules/different-view.js
JSTests/modules/fallback-ambiguous.js
JSTests/modules/import-error.js
JSTests/modules/indirect-export-error.js
JSTests/modules/namespace-error.js
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/jsc.cpp

index d57fdf1..bf5780e 100644 (file)
@@ -1,3 +1,25 @@
+2018-09-08  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Remove loadModule function in jsc.cpp
+        https://bugs.webkit.org/show_bug.cgi?id=184808
+
+        Reviewed by Darin Adler.
+
+        Use `import` expression instead.
+
+        * modules/different-view.js:
+        (from.string_appeared_here.shouldThrow): Deleted.
+        * modules/fallback-ambiguous.js:
+        (from.string_appeared_here.shouldThrow): Deleted.
+        * modules/import-error.js:
+        (from.string_appeared_here.shouldThrow): Deleted.
+        (shouldThrow): Deleted.
+        * modules/indirect-export-error.js:
+        (from.string_appeared_here.shouldThrow): Deleted.
+        (shouldThrow): Deleted.
+        * modules/namespace-error.js:
+        (from.string_appeared_here.shouldThrow): Deleted.
+
 2018-09-07  Mark Lam  <mark.lam@apple.com>
 
         Ensure that handleIntrinsicCall() is only applied on op_call shaped instructions.
index f81e89c..c38b52b 100644 (file)
@@ -1,7 +1,5 @@
-import { shouldBe, shouldThrow } from "./resources/assert.js"
-
-shouldThrow(() => {
-    loadModule('./different-view/main.js');
-}, `SyntaxError: Importing binding name 'A' cannot be resolved due to ambiguous multiple bindings.`);
-
+import { shouldBe } from "./resources/assert.js"
 
+import('./different-view/main.js').then($vm.abort, function (error) {
+    shouldBe(String(error), `SyntaxError: Importing binding name 'A' cannot be resolved due to ambiguous multiple bindings.`);
+}).catch($vm.abort);
index 36b60fe..210ffcd 100644 (file)
@@ -6,7 +6,8 @@
 //        |      |
 //        v      @
 //       (B)
-import { shouldThrow } from "./resources/assert.js"
-shouldThrow(() => {
-    loadModule("./fallback-ambiguous/main.js");
-}, `SyntaxError: Indirectly exported binding name 'A' cannot be resolved due to ambiguous multiple bindings.`);
+import { shouldBe } from "./resources/assert.js"
+
+import('./fallback-ambiguous/main.js').then($vm.abort, function (error) {
+    shouldBe(String(error), `SyntaxError: Indirectly exported binding name 'A' cannot be resolved due to ambiguous multiple bindings.`);
+}).catch($vm.abort);
index 0237472..3b86812 100644 (file)
@@ -1,13 +1,16 @@
-import { shouldBe, shouldThrow } from "./resources/assert.js"
+import { shouldBe } from "./resources/assert.js"
 
-shouldThrow(() => {
-    loadModule('./import-error/import-not-found.js');
-}, `SyntaxError: Importing binding name 'B' is not found.`);
-
-shouldThrow(() => {
-    loadModule('./import-error/import-ambiguous.js');
-}, `SyntaxError: Importing binding name 'B' cannot be resolved due to ambiguous multiple bindings.`);
-
-shouldThrow(() => {
-    loadModule('./import-error/import-default-from-star.js');
-}, `SyntaxError: Importing binding name 'default' cannot be resolved by star export entries.`);
+Promise.all([
+    import('./import-error/import-not-found.js')
+        .then($vm.abort, function (error) {
+            shouldBe(String(error), `SyntaxError: Importing binding name 'B' is not found.`);
+        }).catch($vm.abort),
+    import('./import-error/import-ambiguous.js')
+        .then($vm.abort, function (error) {
+            shouldBe(String(error), `SyntaxError: Importing binding name 'B' cannot be resolved due to ambiguous multiple bindings.`);
+        }).catch($vm.abort),
+    import('./import-error/import-default-from-star.js')
+        .then($vm.abort, function (error) {
+            shouldBe(String(error), `SyntaxError: Importing binding name 'default' cannot be resolved by star export entries.`);
+        }).catch($vm.abort),
+]).catch($vm.abort);
index a3cfc77..41dbebd 100644 (file)
@@ -1,13 +1,17 @@
-import { shouldBe, shouldThrow } from "./resources/assert.js"
+import { shouldBe } from "./resources/assert.js"
 
-shouldThrow(() => {
-    loadModule('./indirect-export-error/indirect-export-not-found.js');
-}, `SyntaxError: Indirectly exported binding name 'B' is not found.`);
 
-shouldThrow(() => {
-    loadModule('./indirect-export-error/indirect-export-ambiguous.js');
-}, `SyntaxError: Indirectly exported binding name 'B' cannot be resolved due to ambiguous multiple bindings.`);
-
-shouldThrow(() => {
-    loadModule('./indirect-export-error/indirect-export-default.js');
-}, `SyntaxError: Indirectly exported binding name 'default' cannot be resolved by star export entries.`);
+Promise.all([
+    import('./indirect-export-error/indirect-export-not-found.js')
+        .then($vm.abort, function (error) {
+            shouldBe(String(error), `SyntaxError: Indirectly exported binding name 'B' is not found.`);
+        }).catch($vm.abort),
+    import('./indirect-export-error/indirect-export-ambiguous.js')
+        .then($vm.abort, function (error) {
+            shouldBe(String(error), `SyntaxError: Indirectly exported binding name 'B' cannot be resolved due to ambiguous multiple bindings.`);
+        }).catch($vm.abort),
+    import('./indirect-export-error/indirect-export-default.js')
+        .then($vm.abort, function (error) {
+            shouldBe(String(error), `SyntaxError: Indirectly exported binding name 'default' cannot be resolved by star export entries.`);
+        }).catch($vm.abort),
+]).catch($vm.abort);
index e47817a..6d6a9ed 100644 (file)
@@ -1,5 +1,5 @@
-import { shouldThrow } from "./resources/assert.js"
+import { shouldBe } from "./resources/assert.js"
 
-shouldThrow(() => {
-    loadModule('./namespace-error/namespace-local-error-should-hide-global-ambiguity.js');
-}, `SyntaxError: Indirectly exported binding name 'default' cannot be resolved by star export entries.`);
+import('./namespace-error/namespace-local-error-should-hide-global-ambiguity.js').then($vm.abort, function (error) {
+    shouldBe(String(error), `SyntaxError: Indirectly exported binding name 'default' cannot be resolved by star export entries.`);
+}).catch($vm.abort);
index 404f76e..1b1f86c 100644 (file)
@@ -1,3 +1,16 @@
+2018-09-08  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Remove loadModule function in jsc.cpp
+        https://bugs.webkit.org/show_bug.cgi?id=184808
+
+        Reviewed by Darin Adler.
+
+        Since we have `import`, we do not need to have `loadModule` function for testing purpose.
+
+        * jsc.cpp:
+        (GlobalObject::finishCreation):
+        (functionLoadModule): Deleted.
+
 2018-09-07  Mark Lam  <mark.lam@apple.com>
 
         Ensure that handleIntrinsicCall() is only applied on op_call shaped instructions.
index 9a66917..5311ac9 100644 (file)
@@ -300,7 +300,6 @@ static EncodedJSValue JSC_HOST_CALL functionHasCustomProperties(ExecState*);
 static EncodedJSValue JSC_HOST_CALL functionDumpTypesForAllVariables(ExecState*);
 static EncodedJSValue JSC_HOST_CALL functionDrainMicrotasks(ExecState*);
 static EncodedJSValue JSC_HOST_CALL functionIs32BitPlatform(ExecState*);
-static EncodedJSValue JSC_HOST_CALL functionLoadModule(ExecState*);
 static EncodedJSValue JSC_HOST_CALL functionCheckModuleSyntax(ExecState*);
 static EncodedJSValue JSC_HOST_CALL functionPlatformSupportsSamplingProfiler(ExecState*);
 static EncodedJSValue JSC_HOST_CALL functionGenerateHeapSnapshot(ExecState*);
@@ -538,7 +537,6 @@ protected:
 
         addFunction(vm, "is32BitPlatform", functionIs32BitPlatform, 0);
 
-        addFunction(vm, "loadModule", functionLoadModule, 1);
         addFunction(vm, "checkModuleSyntax", functionCheckModuleSyntax, 1);
 
         addFunction(vm, "platformSupportsSamplingProfiler", functionPlatformSupportsSamplingProfiler, 0);
@@ -1964,34 +1962,6 @@ EncodedJSValue JSC_HOST_CALL functionIs32BitPlatform(ExecState*)
 #endif
 }
 
-EncodedJSValue JSC_HOST_CALL functionLoadModule(ExecState* exec)
-{
-    VM& vm = exec->vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-
-    String fileName = exec->argument(0).toWTFString(exec);
-    RETURN_IF_EXCEPTION(scope, encodedJSValue());
-    Vector<char> script;
-    if (!fetchScriptFromLocalFileSystem(fileName, script))
-        return JSValue::encode(throwException(exec, scope, createError(exec, "Could not open file."_s)));
-
-    JSInternalPromise* promise = loadAndEvaluateModule(exec, fileName, jsUndefined(), jsUndefined());
-    RETURN_IF_EXCEPTION(scope, encodedJSValue());
-
-    JSValue error;
-    JSFunction* errorHandler = JSNativeStdFunction::create(vm, exec->lexicalGlobalObject(), 1, String(), [&](ExecState* exec) {
-        error = exec->argument(0);
-        return JSValue::encode(jsUndefined());
-    });
-
-    promise->then(exec, nullptr, errorHandler);
-    RETURN_IF_EXCEPTION(scope, encodedJSValue());
-    vm.drainMicrotasks();
-    if (error)
-        return JSValue::encode(throwException(exec, scope, error));
-    return JSValue::encode(jsUndefined());
-}
-
 EncodedJSValue JSC_HOST_CALL functionCreateGlobalObject(ExecState* exec)
 {
     VM& vm = exec->vm();