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

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

Issue 2566513002: Create bare-bones ScriptModule class (Closed)
Patch Set: Add more TODOs Created 3 years, 11 months 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 // TODO(adamk): This method should either live in V8ScriptRunner or call out
17 // to code there.
18 ScriptModule ScriptModule::compile(v8::Isolate* isolate,
19 const String& source,
20 const String& fileName) {
21 // TODO(adamk): Pass more info into ScriptOrigin.
22 v8::ScriptOrigin origin(v8String(isolate, fileName));
23 v8::ScriptCompiler::Source scriptSource(v8String(isolate, source), origin);
24 v8::TryCatch tryCatch(isolate);
25 tryCatch.SetVerbose(true);
26 v8::Local<v8::Module> module;
27 if (!v8Call(v8::ScriptCompiler::CompileModule(isolate, &scriptSource), module,
haraken 2017/01/11 02:21:35 I want to create a helper function in V8ScriptRunn
adamk 2017/01/11 18:27:30 Ok added a helper to V8ScriptRunner with some basi
28 tryCatch)) {
29 // TODO(adamk): Signal failure somehow.
30 return ScriptModule(isolate, module);
31 }
32 return ScriptModule(isolate, module);
33 }
34
35 v8::MaybeLocal<v8::Module> dummyCallback(v8::Local<v8::Context> context,
36 v8::Local<v8::String> specifier,
37 v8::Local<v8::Module> referrer) {
38 return v8::MaybeLocal<v8::Module>();
39 }
40
41 bool ScriptModule::instantiate(ScriptState* scriptState) {
42 DCHECK(!isNull());
43 v8::Local<v8::Context> context = scriptState->context();
44 // TODO(adamk): pass in a real callback.
45 return m_module->newLocal(scriptState->isolate())
46 ->Instantiate(context, &dummyCallback);
haraken 2017/01/11 02:21:35 Can we make V8 accept a nullptr as a callback?
adamk 2017/01/11 18:27:30 There's not a good use for such a thing in the mod
47 }
48
49 // TODO(adamk): This method should either live in V8ScriptRunner or call out
50 // to code there.
haraken 2017/01/11 02:21:35 Yes, I'd prefer moving the Evaluate call to V8Scri
adamk 2017/01/11 18:27:30 Done
51 void ScriptModule::evaluate(ScriptState* scriptState) {
52 v8::TryCatch tryCatch(scriptState->isolate());
53 tryCatch.SetVerbose(true);
54 v8::Local<v8::Value> result;
55 if (!v8Call(m_module->newLocal(scriptState->isolate())
56 ->Evaluate(scriptState->context()),
57 result, tryCatch)) {
58 // TODO(adamk): report error
59 }
60 }
61
62 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698