Web Inspector: allow import() inside the inspector
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Feb 2017 17:32:12 +0000 (17:32 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Feb 2017 17:32:12 +0000 (17:32 +0000)
commit5916be2163f38dde7bebeb4657ee89633cd907f1
tree876e896c6ecc24ecd765e4d76f978a10e28b56df
parent4b6af65b2f219753dbe17b41daac54941aeccf34
Web Inspector: allow import() inside the inspector
https://bugs.webkit.org/show_bug.cgi?id=167457

Reviewed by Ryosuke Niwa.

Source/JavaScriptCore:

We relax import module hook to accept null SourceOrigin.
Such a script can be evaluated from the inspector console.

* jsc.cpp:
(GlobalObject::moduleLoaderImportModule):
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::globalFuncImportModule):

Source/WebCore:

When evaluating `import("...")`, we need the caller's context to resolve
the module specifier correctly. For example, if `import("./cocoa.js")` is
evaluated in the script "drinks/hot.js", this module name is resolved to
"drinks/cocoa.js". If the same import operator is evaluated in the script
"menu/all.js", the module specifier becomes "menu/cocoa.js".

Previously we reject the import operator if the caller does not have such
a context. These context is SourceOrigin and its ScriptFetcher. While they
are offered in the script tag and other code evaluations, the inspector
console does not offer that. These class are offered in the WebCore side
and we should not touch these classes in the JSC's inspector code.

Now we relax the above restriction. If the above caller information is not
offered, we fallback to the default one. In the web page, we use the page's
URL as the caller's source origin. This allows us to evaluate the import
operator in the inspector console.

And as of r167698, the console recognizes `await import("...")` form. We use
this to test this `import()` in the console functionality.

Test: inspector/controller/runtime-controller-import.html

* bindings/js/ScriptModuleLoader.cpp:
(WebCore::ScriptModuleLoader::importModule):

LayoutTests:

Extract the test to single file. And make it deterministic.

* inspector/controller/resources/cappuccino.js: Added.
* inspector/controller/resources/cocoa.js: Added.
* inspector/controller/resources/drink.js: Added.
* inspector/controller/runtime-controller-import-expected.txt: Added.
* inspector/controller/runtime-controller-import.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212438 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/inspector/controller/resources/cappuccino.js [new file with mode: 0644]
LayoutTests/inspector/controller/resources/cocoa.js [new file with mode: 0644]
LayoutTests/inspector/controller/resources/drink.js [new file with mode: 0644]
LayoutTests/inspector/controller/runtime-controller-import-expected.txt [new file with mode: 0644]
LayoutTests/inspector/controller/runtime-controller-import.html [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/jsc.cpp
Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/ScriptModuleLoader.cpp