Commit 01824e5e authored by adamk's avatar adamk Committed by Commit bot

[modules] Move Evaluate from api.cc into internal Module implementation

R=neis@chromium.org
BUG=v8:1569

Review-Url: https://codereview.chromium.org/2376693003
Cr-Commit-Position: refs/heads/master@{#39790}
parent 4810f41a
......@@ -1937,29 +1937,8 @@ MaybeLocal<Value> Module::Evaluate(Local<Context> context) {
// It's an API error to call Evaluate before Instantiate.
CHECK(self->code()->IsJSFunction());
// Each module can only be evaluated once.
if (self->evaluated()) return Undefined(reinterpret_cast<Isolate*>(isolate));
self->set_evaluated(true);
i::Handle<i::FixedArray> requested_modules(self->requested_modules(),
isolate);
for (int i = 0, length = requested_modules->length(); i < length; ++i) {
i::Handle<i::Module> import(i::Module::cast(requested_modules->get(i)),
isolate);
MaybeLocal<Value> maybe_result = Utils::ToLocal(import)->Evaluate(context);
if (maybe_result.IsEmpty()) return maybe_result;
}
i::Handle<i::JSFunction> function(i::JSFunction::cast(self->code()), isolate);
DCHECK_EQ(i::MODULE_SCOPE, function->shared()->scope_info()->scope_type());
i::Handle<i::Object> receiver = isolate->factory()->undefined_value();
Local<Value> result;
i::Handle<i::Object> argv[] = {self};
has_pending_exception = !ToLocal<Value>(
i::Execution::Call(isolate, function, receiver, arraysize(argv), argv),
&result);
has_pending_exception = !ToLocal(i::Module::Evaluate(self), &result);
RETURN_ON_FAILED_EXECUTION(Value);
RETURN_ESCAPED(result);
}
......
......@@ -19903,5 +19903,27 @@ bool Module::Instantiate(Handle<Module> module, v8::Local<v8::Context> context,
return true;
}
MaybeHandle<Object> Module::Evaluate(Handle<Module> module) {
DCHECK(module->code()->IsJSFunction());
Isolate* isolate = module->GetIsolate();
// Each module can only be evaluated once.
if (module->evaluated()) return isolate->factory()->undefined_value();
module->set_evaluated(true);
Handle<FixedArray> requested_modules(module->requested_modules(), isolate);
for (int i = 0, length = requested_modules->length(); i < length; ++i) {
Handle<Module> import(Module::cast(requested_modules->get(i)), isolate);
RETURN_ON_EXCEPTION(isolate, Evaluate(import), Object);
}
Handle<JSFunction> function(JSFunction::cast(module->code()), isolate);
DCHECK_EQ(MODULE_SCOPE, function->shared()->scope_info()->scope_type());
Handle<Object> receiver = isolate->factory()->undefined_value();
Handle<Object> argv[] = {module};
return Execution::Call(isolate, function, receiver, arraysize(argv), argv);
}
} // namespace internal
} // namespace v8
......@@ -7967,6 +7967,9 @@ class Module : public Struct {
v8::Module::ResolveCallback callback,
v8::Local<v8::Value> callback_data);
// Implementation of spec operation ModuleEvaluation.
static MUST_USE_RESULT MaybeHandle<Object> Evaluate(Handle<Module> module);
static Handle<Object> LoadExport(Handle<Module> module, Handle<String> name);
static void StoreExport(Handle<Module> module, Handle<String> name,
Handle<Object> value);
......
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