Commit 419d8078 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

Worklet: Reject dynamic import() on WorkletGlobalScope

All networking APIs including dynamic import() are disallowed on
WorkletGlobalScope. This CL makes dynamic import() always reject a promise with
TypeError[1] on WorkletGlobalScope.

[1] https://github.com/w3c/css-houdini-drafts/issues/506#issuecomment-344488690

Bug: 782538
Change-Id: Ieb94a4502b0ba35ff9b56e51c8fc34467ab96d0c
Reviewed-on: https://chromium-review.googlesource.com/790059
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarHiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521295}
parent 894f7bbf
CONSOLE MESSAGE: line 9: This test logs a result once from each PaintWorkletGlobalScope
CONSOLE ERROR: line 3: TypeError: import() is disallowed on WorkletGlobalScope.
CONSOLE ERROR: line 3: TypeError: import() is disallowed on WorkletGlobalScope.
This is a testharness.js-based test.
PASS Dynamic import() on WorkletGlobalScope should reject the promise.
Harness: the test ran to completion.
<!DOCTYPE html>
<title>Worklet: Dynamic import() on WorkletGlobalScope</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
// This test should not be upstreamed to WPT because this tests console outputs.
console.log('This test logs a result once from each PaintWorkletGlobalScope');
promise_test(() => {
const kScriptURL = 'resources/dynamic-import-worklet-script.js';
return CSS.paintWorklet.addModule(kScriptURL)
.then(result => assert_equals(undefined, result));
}, 'Dynamic import() on WorkletGlobalScope should reject the promise.');
</script>
import('./empty-worklet-script.js')
.then(() => console.error('Should not reach here.'))
.catch(e => console.error(e.name + ': ' + e.message));
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
#include "core/dom/WorkletModulatorImpl.h" #include "core/dom/WorkletModulatorImpl.h"
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "core/loader/modulescript/WorkletModuleScriptFetcher.h" #include "core/loader/modulescript/WorkletModuleScriptFetcher.h"
#include "core/workers/WorkletGlobalScope.h" #include "core/workers/WorkletGlobalScope.h"
#include "platform/bindings/V8ThrowException.h"
namespace blink { namespace blink {
...@@ -28,4 +30,13 @@ ModuleScriptFetcher* WorkletModulatorImpl::CreateModuleScriptFetcher() { ...@@ -28,4 +30,13 @@ ModuleScriptFetcher* WorkletModulatorImpl::CreateModuleScriptFetcher() {
global_scope->ModuleResponsesMapProxy()); global_scope->ModuleResponsesMapProxy());
} }
void WorkletModulatorImpl::ResolveDynamically(const String&,
const KURL&,
const ReferrerScriptInfo&,
ScriptPromiseResolver* resolver) {
resolver->Reject(V8ThrowException::CreateTypeError(
GetScriptState()->GetIsolate(),
"import() is disallowed on WorkletGlobalScope."));
}
} // namespace blink } // namespace blink
...@@ -21,12 +21,18 @@ class WorkletModulatorImpl final : public ModulatorImplBase { ...@@ -21,12 +21,18 @@ class WorkletModulatorImpl final : public ModulatorImplBase {
public: public:
static ModulatorImplBase* Create(scoped_refptr<ScriptState>); static ModulatorImplBase* Create(scoped_refptr<ScriptState>);
// Implements Modulator. // Implements ModulatorImplBase.
SecurityOrigin* GetSecurityOriginForFetch() override; SecurityOrigin* GetSecurityOriginForFetch() override;
ModuleScriptFetcher* CreateModuleScriptFetcher() override; ModuleScriptFetcher* CreateModuleScriptFetcher() override;
private: private:
explicit WorkletModulatorImpl(scoped_refptr<ScriptState>); explicit WorkletModulatorImpl(scoped_refptr<ScriptState>);
// Implements ModulatorImplBase.
void ResolveDynamically(const String& specifier,
const KURL&,
const ReferrerScriptInfo&,
ScriptPromiseResolver*) final;
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment