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

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

Issue 2566513002: Create bare-bones ScriptModule class (Closed)
Patch Set: haraken comments 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.
haraken 2017/01/11 23:40:59 2017
adamk 2017/01/11 23:43:15 Done.
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 v8::TryCatch tryCatch(isolate);
20 tryCatch.SetVerbose(true);
21 v8::Local<v8::Module> module;
22 if (!v8Call(V8ScriptRunner::compileModule(isolate, source, fileName), module,
23 tryCatch)) {
24 // TODO(adamk): Signal failure somehow.
25 return ScriptModule(isolate, module);
26 }
27 return ScriptModule(isolate, module);
28 }
29
30 v8::MaybeLocal<v8::Module> dummyCallback(v8::Local<v8::Context> context,
31 v8::Local<v8::String> specifier,
32 v8::Local<v8::Module> referrer) {
33 return v8::MaybeLocal<v8::Module>();
34 }
35
36 bool ScriptModule::instantiate(ScriptState* scriptState) {
37 DCHECK(!isNull());
38 v8::Local<v8::Context> context = scriptState->context();
39 // TODO(adamk): pass in a real callback.
40 return m_module->newLocal(scriptState->isolate())
41 ->Instantiate(context, &dummyCallback);
42 }
43
44 void ScriptModule::evaluate(ScriptState* scriptState) {
45 v8::Isolate* isolate = scriptState->isolate();
46 v8::TryCatch tryCatch(isolate);
47 tryCatch.SetVerbose(true);
48 v8::Local<v8::Value> result;
49 if (!v8Call(V8ScriptRunner::evaluateModule(m_module->newLocal(isolate),
50 scriptState->context(), isolate),
51 result, tryCatch)) {
52 // TODO(adamk): report error
53 }
54 }
55
56 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698