Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp

Issue 2555653002: [WIP Prototype] ES6 https://html.spec.whatwg.org/#fetch-a-single-module-script implementation (Closed)
Patch Set: WIP: ModuleLoaderClient && crafts to make it work even if notifyFinished adds another ModuleLoaderC… Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "bindings/core/v8/ScriptModule.h"
6
7 #include "bindings/core/v8/V8Binding.h"
8
9 namespace blink {
10
11 ScriptModule::ScriptModule(v8::Isolate* isolate, v8::Local<v8::Module> module)
12 : m_module(SharedPersistent<v8::Module>::create(module, isolate)) {}
13
14 ScriptModule::~ScriptModule() {}
15
16 ScriptModule ScriptModule::compile(v8::Isolate* isolate,
17 const String& source,
18 const String& fileName) {
19 // TODO(adamk): Pass more info into ScriptOrigin.
20 v8::ScriptOrigin origin(v8String(isolate, fileName));
21 v8::ScriptCompiler::Source scriptSource(v8String(isolate, source), origin);
22 v8::TryCatch tryCatch(isolate);
23 tryCatch.SetVerbose(true);
24 v8::Local<v8::Module> module;
25 if (!v8Call(v8::ScriptCompiler::CompileModule(isolate, &scriptSource), module,
26 tryCatch)) {
27 // TODO(adamk): Signal failure somehow.
28 return ScriptModule(isolate, module);
29 }
30 return ScriptModule(isolate, module);
31 }
32
33 v8::MaybeLocal<v8::Module> dummyCallback(v8::Local<v8::Context> context,
34 v8::Local<v8::String> specifier,
35 v8::Local<v8::Module> referrer) {
36 return v8::MaybeLocal<v8::Module>();
37 }
38
39 bool ScriptModule::instantiate(ScriptState* scriptState) {
40 DCHECK(!isNull());
41 v8::Local<v8::Context> context = scriptState->context();
42 // TODO(adamk): pass in a real callback.
43 return m_module->newLocal(scriptState->isolate())
44 ->Instantiate(context, &dummyCallback);
45 }
46
47 void ScriptModule::evaluate(ScriptState* scriptState) {
48 v8::TryCatch tryCatch(scriptState->isolate());
49 tryCatch.SetVerbose(true);
50 v8::Local<v8::Value> result;
51 if (!v8Call(m_module->newLocal(scriptState->isolate())
52 ->Evaluate(scriptState->context()),
53 result, tryCatch)) {
54 // TODO(adamk): report error
55 }
56 }
57
58 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698