summaryrefslogtreecommitdiff
path: root/deps/v8/src
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src')
-rw-r--r--deps/v8/src/api/api.cc28
-rw-r--r--deps/v8/src/logging/counters.h1
-rw-r--r--deps/v8/src/objects/synthetic-module.cc30
-rw-r--r--deps/v8/src/objects/synthetic-module.h18
4 files changed, 66 insertions, 11 deletions
diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc
index cb503015c1..fffee36c5a 100644
--- a/deps/v8/src/api/api.cc
+++ b/deps/v8/src/api/api.cc
@@ -2362,6 +2362,28 @@ Local<Module> Module::CreateSyntheticModule(
i_module_name, i_export_names, evaluation_steps)));
}
+Maybe<bool> Module::SetSyntheticModuleExport(Isolate* isolate,
+ Local<String> export_name,
+ Local<v8::Value> export_value) {
+ auto i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ i::Handle<i::String> i_export_name = Utils::OpenHandle(*export_name);
+ i::Handle<i::Object> i_export_value = Utils::OpenHandle(*export_value);
+ i::Handle<i::Module> self = Utils::OpenHandle(this);
+ Utils::ApiCheck(self->IsSyntheticModule(),
+ "v8::Module::SyntheticModuleSetExport",
+ "v8::Module::SyntheticModuleSetExport must only be called on "
+ "a SyntheticModule");
+ ENTER_V8_NO_SCRIPT(i_isolate, isolate->GetCurrentContext(), Module,
+ SetSyntheticModuleExport, Nothing<bool>(), i::HandleScope);
+ has_pending_exception =
+ i::SyntheticModule::SetExport(i_isolate,
+ i::Handle<i::SyntheticModule>::cast(self),
+ i_export_name, i_export_value)
+ .IsNothing();
+ RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
+ return Just(true);
+}
+
void Module::SetSyntheticModuleExport(Local<String> export_name,
Local<v8::Value> export_value) {
i::Handle<i::String> i_export_name = Utils::OpenHandle(*export_name);
@@ -2371,9 +2393,9 @@ void Module::SetSyntheticModuleExport(Local<String> export_name,
"v8::Module::SetSyntheticModuleExport",
"v8::Module::SetSyntheticModuleExport must only be called on "
"a SyntheticModule");
- i::SyntheticModule::SetExport(self->GetIsolate(),
- i::Handle<i::SyntheticModule>::cast(self),
- i_export_name, i_export_value);
+ i::SyntheticModule::SetExportStrict(self->GetIsolate(),
+ i::Handle<i::SyntheticModule>::cast(self),
+ i_export_name, i_export_value);
}
namespace {
diff --git a/deps/v8/src/logging/counters.h b/deps/v8/src/logging/counters.h
index 5ba1d4626e..d82515efba 100644
--- a/deps/v8/src/logging/counters.h
+++ b/deps/v8/src/logging/counters.h
@@ -783,6 +783,7 @@ class RuntimeCallTimer final {
V(Message_GetStartColumn) \
V(Module_Evaluate) \
V(Module_InstantiateModule) \
+ V(Module_SetSyntheticModuleExport) \
V(NumberObject_New) \
V(NumberObject_NumberValue) \
V(Object_CallAsConstructor) \
diff --git a/deps/v8/src/objects/synthetic-module.cc b/deps/v8/src/objects/synthetic-module.cc
index 58e0c1b58c..75e79e8955 100644
--- a/deps/v8/src/objects/synthetic-module.cc
+++ b/deps/v8/src/objects/synthetic-module.cc
@@ -17,16 +17,36 @@ namespace internal {
// Implements SetSyntheticModuleBinding:
// https://heycam.github.io/webidl/#setsyntheticmoduleexport
-void SyntheticModule::SetExport(Isolate* isolate,
- Handle<SyntheticModule> module,
- Handle<String> export_name,
- Handle<Object> export_value) {
+Maybe<bool> SyntheticModule::SetExport(Isolate* isolate,
+ Handle<SyntheticModule> module,
+ Handle<String> export_name,
+ Handle<Object> export_value) {
Handle<ObjectHashTable> exports(module->exports(), isolate);
Handle<Object> export_object(exports->Lookup(export_name), isolate);
- CHECK(export_object->IsCell());
+
+ if (!export_object->IsCell()) {
+ isolate->Throw(*isolate->factory()->NewReferenceError(
+ MessageTemplate::kModuleExportUndefined, export_name));
+ return Nothing<bool>();
+ }
+
Handle<Cell> export_cell(Handle<Cell>::cast(export_object));
// Spec step 2: Set the mutable binding of export_name to export_value
export_cell->set_value(*export_value);
+
+ return Just(true);
+}
+
+void SyntheticModule::SetExportStrict(Isolate* isolate,
+ Handle<SyntheticModule> module,
+ Handle<String> export_name,
+ Handle<Object> export_value) {
+ Handle<ObjectHashTable> exports(module->exports(), isolate);
+ Handle<Object> export_object(exports->Lookup(export_name), isolate);
+ CHECK(export_object->IsCell());
+ Maybe<bool> set_export_result =
+ SetExport(isolate, module, export_name, export_value);
+ CHECK(set_export_result.FromJust());
}
// Implements Synthetic Module Record's ResolveExport concrete method:
diff --git a/deps/v8/src/objects/synthetic-module.h b/deps/v8/src/objects/synthetic-module.h
index 6f3bb0438e..77a6eed276 100644
--- a/deps/v8/src/objects/synthetic-module.h
+++ b/deps/v8/src/objects/synthetic-module.h
@@ -24,9 +24,21 @@ class SyntheticModule
DECL_VERIFIER(SyntheticModule)
DECL_PRINTER(SyntheticModule)
- static void SetExport(Isolate* isolate, Handle<SyntheticModule> module,
- Handle<String> export_name,
- Handle<Object> export_value);
+ // Set module's exported value for the specified export_name to the specified
+ // export_value. An error will be thrown if export_name is not one
+ // of the export_names that were supplied during module construction.
+ // Returns Just(true) on success, Nothing<bool>() if an error was thrown.
+ static Maybe<bool> SetExport(Isolate* isolate, Handle<SyntheticModule> module,
+ Handle<String> export_name,
+ Handle<Object> export_value);
+ // The following redundant method should be deleted when the deprecated
+ // version of v8::SetSyntheticModuleExport is removed. It differs from
+ // SetExport in that it crashes rather than throwing an error if the caller
+ // attempts to set an export_name that was not present during construction of
+ // the module.
+ static void SetExportStrict(Isolate* isolate, Handle<SyntheticModule> module,
+ Handle<String> export_name,
+ Handle<Object> export_value);
using BodyDescriptor = SubclassBodyDescriptor<
Module::BodyDescriptor,