| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 824e8b6 commit 5131bbe
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,7 +39,7 @@ | |||
| 39 | 39 | ||
| 40 | 40 | # Reset this number to 0 on major V8 upgrades. | |
| 41 | 41 | # Increment by one for each non-official patch applied to deps/v8. | |
| 42 | - 'v8_embedder_string': '-node.14', | ||
| 42 | + 'v8_embedder_string': '-node.15', | ||
| 43 | 43 | ||
| 44 | 44 | ##### V8 defaults for Node.js ##### | |
| 45 | 45 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1560,9 +1560,17 @@ class V8_EXPORT Module : public Data { | |||
| 1560 | 1560 | /** | |
| 1561 | 1561 | * Set this module's exported value for the name export_name to the specified | |
| 1562 | 1562 | * export_value. This method must be called only on Modules created via | |
| 1563 | - * CreateSyntheticModule. export_name must be one of the export_names that | ||
| 1564 | - * were passed in that CreateSyntheticModule call. | ||
| 1563 | + * CreateSyntheticModule. An error will be thrown if export_name is not one | ||
| 1564 | + * of the export_names that were passed in that CreateSyntheticModule call. | ||
| 1565 | + * Returns Just(true) on success, Nothing<bool>() if an error was thrown. | ||
| 1565 | 1566 | */ | |
| 1567 | + V8_WARN_UNUSED_RESULT Maybe<bool> SetSyntheticModuleExport( | ||
| 1568 | + Isolate* isolate, Local<String> export_name, Local<Value> export_value); | ||
| 1569 | + V8_DEPRECATE_SOON( | ||
| 1570 | + "Use the preceding SetSyntheticModuleExport with an Isolate parameter, " | ||
| 1571 | + "instead of the one that follows. The former will throw a runtime " | ||
| 1572 | + "error if called for an export that doesn't exist (as per spec); " | ||
| 1573 | + "the latter will crash with a failed CHECK().") | ||
| 1566 | 1574 | void SetSyntheticModuleExport(Local<String> export_name, | |
| 1567 | 1575 | Local<Value> export_value); | |
| 1568 | 1576 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2362,6 +2362,28 @@ Local<Module> Module::CreateSyntheticModule( | |||
| 2362 | 2362 | i_module_name, i_export_names, evaluation_steps))); | |
| 2363 | 2363 | } | |
| 2364 | 2364 | ||
| 2365 | + Maybe<bool> Module::SetSyntheticModuleExport(Isolate* isolate, | ||
| 2366 | + Local<String> export_name, | ||
| 2367 | + Local<v8::Value> export_value) { | ||
| 2368 | + auto i_isolate = reinterpret_cast<i::Isolate*>(isolate); | ||
| 2369 | + i::Handle<i::String> i_export_name = Utils::OpenHandle(*export_name); | ||
| 2370 | + i::Handle<i::Object> i_export_value = Utils::OpenHandle(*export_value); | ||
| 2371 | + i::Handle<i::Module> self = Utils::OpenHandle(this); | ||
| 2372 | + Utils::ApiCheck(self->IsSyntheticModule(), | ||
| 2373 | + "v8::Module::SyntheticModuleSetExport", | ||
| 2374 | + "v8::Module::SyntheticModuleSetExport must only be called on " | ||
| 2375 | + "a SyntheticModule"); | ||
| 2376 | + ENTER_V8_NO_SCRIPT(i_isolate, isolate->GetCurrentContext(), Module, | ||
| 2377 | + SetSyntheticModuleExport, Nothing<bool>(), i::HandleScope); | ||
| 2378 | + has_pending_exception = | ||
| 2379 | + i::SyntheticModule::SetExport(i_isolate, | ||
| 2380 | + i::Handle<i::SyntheticModule>::cast(self), | ||
| 2381 | + i_export_name, i_export_value) | ||
| 2382 | + .IsNothing(); | ||
| 2383 | + RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | ||
| 2384 | + return Just(true); | ||
| 2385 | + } | ||
| 2386 | + | ||
| 2365 | 2387 | void Module::SetSyntheticModuleExport(Local<String> export_name, | |
| 2366 | 2388 | Local<v8::Value> export_value) { | |
| 2367 | 2389 | i::Handle<i::String> i_export_name = Utils::OpenHandle(*export_name); | |
@@ -2371,9 +2393,9 @@ void Module::SetSyntheticModuleExport(Local<String> export_name, | |||
| 2371 | 2393 | "v8::Module::SetSyntheticModuleExport", | |
| 2372 | 2394 | "v8::Module::SetSyntheticModuleExport must only be called on " | |
| 2373 | 2395 | "a SyntheticModule"); | |
| 2374 | - i::SyntheticModule::SetExport(self->GetIsolate(), | ||
| 2375 | - i::Handle<i::SyntheticModule>::cast(self), | ||
| 2376 | - i_export_name, i_export_value); | ||
| 2396 | + i::SyntheticModule::SetExportStrict(self->GetIsolate(), | ||
| 2397 | + i::Handle<i::SyntheticModule>::cast(self), | ||
| 2398 | + i_export_name, i_export_value); | ||
| 2377 | 2399 | } | |
| 2378 | 2400 | ||
| 2379 | 2401 | namespace { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -783,6 +783,7 @@ class RuntimeCallTimer final { | |||
| 783 | 783 | V(Message_GetStartColumn) \ | |
| 784 | 784 | V(Module_Evaluate) \ | |
| 785 | 785 | V(Module_InstantiateModule) \ | |
| 786 | + V(Module_SetSyntheticModuleExport) \ | ||
| 786 | 787 | V(NumberObject_New) \ | |
| 787 | 788 | V(NumberObject_NumberValue) \ | |
| 788 | 789 | V(Object_CallAsConstructor) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,16 +17,36 @@ namespace internal { | |||
| 17 | 17 | ||
| 18 | 18 | // Implements SetSyntheticModuleBinding: | |
| 19 | 19 | // https://heycam.github.io/webidl/#setsyntheticmoduleexport | |
| 20 | - void SyntheticModule::SetExport(Isolate* isolate, | ||
| 21 | - Handle<SyntheticModule> module, | ||
| 22 | - Handle<String> export_name, | ||
| 23 | - Handle<Object> export_value) { | ||
| 20 | + Maybe<bool> SyntheticModule::SetExport(Isolate* isolate, | ||
| 21 | + Handle<SyntheticModule> module, | ||
| 22 | + Handle<String> export_name, | ||
| 23 | + Handle<Object> export_value) { | ||
| 24 | 24 | Handle<ObjectHashTable> exports(module->exports(), isolate); | |
| 25 | 25 | Handle<Object> export_object(exports->Lookup(export_name), isolate); | |
| 26 | - CHECK(export_object->IsCell()); | ||
| 26 | + | ||
| 27 | + if (!export_object->IsCell()) { | ||
| 28 | + isolate->Throw(*isolate->factory()->NewReferenceError( | ||
| 29 | + MessageTemplate::kModuleExportUndefined, export_name)); | ||
| 30 | + return Nothing<bool>(); | ||
| 31 | + } | ||
| 32 | + | ||
| 27 | 33 | Handle<Cell> export_cell(Handle<Cell>::cast(export_object)); | |
| 28 | 34 | // Spec step 2: Set the mutable binding of export_name to export_value | |
| 29 | 35 | export_cell->set_value(*export_value); | |
| 36 | + | ||
| 37 | + return Just(true); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + void SyntheticModule::SetExportStrict(Isolate* isolate, | ||
| 41 | + Handle<SyntheticModule> module, | ||
| 42 | + Handle<String> export_name, | ||
| 43 | + Handle<Object> export_value) { | ||
| 44 | + Handle<ObjectHashTable> exports(module->exports(), isolate); | ||
| 45 | + Handle<Object> export_object(exports->Lookup(export_name), isolate); | ||
| 46 | + CHECK(export_object->IsCell()); | ||
| 47 | + Maybe<bool> set_export_result = | ||
| 48 | + SetExport(isolate, module, export_name, export_value); | ||
| 49 | + CHECK(set_export_result.FromJust()); | ||
| 30 | 50 | } | |
| 31 | 51 | ||
| 32 | 52 | // Implements Synthetic Module Record's ResolveExport concrete method: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,9 +24,21 @@ class SyntheticModule | |||
| 24 | 24 | DECL_VERIFIER(SyntheticModule) | |
| 25 | 25 | DECL_PRINTER(SyntheticModule) | |
| 26 | 26 | ||
| 27 | - static void SetExport(Isolate* isolate, Handle<SyntheticModule> module, | ||
| 28 | - Handle<String> export_name, | ||
| 29 | - Handle<Object> export_value); | ||
| 27 | + // Set module's exported value for the specified export_name to the specified | ||
| 28 | + // export_value. An error will be thrown if export_name is not one | ||
| 29 | + // of the export_names that were supplied during module construction. | ||
| 30 | + // Returns Just(true) on success, Nothing<bool>() if an error was thrown. | ||
| 31 | + static Maybe<bool> SetExport(Isolate* isolate, Handle<SyntheticModule> module, | ||
| 32 | + Handle<String> export_name, | ||
| 33 | + Handle<Object> export_value); | ||
| 34 | + // The following redundant method should be deleted when the deprecated | ||
| 35 | + // version of v8::SetSyntheticModuleExport is removed. It differs from | ||
| 36 | + // SetExport in that it crashes rather than throwing an error if the caller | ||
| 37 | + // attempts to set an export_name that was not present during construction of | ||
| 38 | + // the module. | ||
| 39 | + static void SetExportStrict(Isolate* isolate, Handle<SyntheticModule> module, | ||
| 40 | + Handle<String> export_name, | ||
| 41 | + Handle<Object> export_value); | ||
| 30 | 42 | ||
| 31 | 43 | using BodyDescriptor = SubclassBodyDescriptor< | |
| 32 | 44 | Module::BodyDescriptor, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23721,7 +23721,9 @@ v8::MaybeLocal<Value> SyntheticModuleEvaluationStepsCallbackFail( | |||
| 23721 | 23721 | ||
| 23722 | 23722 | v8::MaybeLocal<Value> SyntheticModuleEvaluationStepsCallbackSetExport( | |
| 23723 | 23723 | Local<Context> context, Local<Module> module) { | |
| 23724 | - module->SetSyntheticModuleExport(v8_str("test_export"), v8_num(42)); | ||
| 23724 | + Maybe<bool> set_export_result = module->SetSyntheticModuleExport( | ||
| 23725 | + context->GetIsolate(), v8_str("test_export"), v8_num(42)); | ||
| 23726 | + CHECK(set_export_result.FromJust()); | ||
| 23725 | 23727 | return v8::Undefined(reinterpret_cast<v8::Isolate*>(context->GetIsolate())); | |
| 23726 | 23728 | } | |
| 23727 | 23729 | ||
@@ -23940,7 +23942,9 @@ TEST(SyntheticModuleSetExports) { | |||
| 23940 | 23942 | // undefined. | |
| 23941 | 23943 | CHECK(foo_cell->value().IsUndefined()); | |
| 23942 | 23944 | ||
| 23943 | - module->SetSyntheticModuleExport(foo_string, bar_string); | ||
| 23945 | + Maybe<bool> set_export_result = | ||
| 23946 | + module->SetSyntheticModuleExport(isolate, foo_string, bar_string); | ||
| 23947 | + CHECK(set_export_result.FromJust()); | ||
| 23944 | 23948 | ||
| 23945 | 23949 | // After setting the export the Cell should still have the same idenitity. | |
| 23946 | 23950 | CHECK_EQ(exports->Lookup(v8::Utils::OpenHandle(*foo_string)), *foo_cell); | |
@@ -23951,6 +23955,34 @@ TEST(SyntheticModuleSetExports) { | |||
| 23951 | 23955 | ->Equals(*v8::Utils::OpenHandle(*bar_string))); | |
| 23952 | 23956 | } | |
| 23953 | 23957 | ||
| 23958 | + TEST(SyntheticModuleSetMissingExport) { | ||
| 23959 | + LocalContext env; | ||
| 23960 | + v8::Isolate* isolate = env->GetIsolate(); | ||
| 23961 | + auto i_isolate = reinterpret_cast<i::Isolate*>(isolate); | ||
| 23962 | + v8::Isolate::Scope iscope(isolate); | ||
| 23963 | + v8::HandleScope scope(isolate); | ||
| 23964 | + v8::Local<v8::Context> context = v8::Context::New(isolate); | ||
| 23965 | + v8::Context::Scope cscope(context); | ||
| 23966 | + | ||
| 23967 | + Local<String> foo_string = v8_str("foo"); | ||
| 23968 | + Local<String> bar_string = v8_str("bar"); | ||
| 23969 | + | ||
| 23970 | + Local<Module> module = CreateAndInstantiateSyntheticModule( | ||
| 23971 | + isolate, v8_str("SyntheticModuleSetExports-TestSyntheticModule"), context, | ||
| 23972 | + std::vector<v8::Local<v8::String>>(), | ||
| 23973 | + UnexpectedSyntheticModuleEvaluationStepsCallback); | ||
| 23974 | + | ||
| 23975 | + i::Handle<i::SyntheticModule> i_module = | ||
| 23976 | + i::Handle<i::SyntheticModule>::cast(v8::Utils::OpenHandle(*module)); | ||
| 23977 | + i::Handle<i::ObjectHashTable> exports(i_module->exports(), i_isolate); | ||
| 23978 | + | ||
| 23979 | + TryCatch try_catch(isolate); | ||
| 23980 | + Maybe<bool> set_export_result = | ||
| 23981 | + module->SetSyntheticModuleExport(isolate, foo_string, bar_string); | ||
| 23982 | + CHECK(set_export_result.IsNothing()); | ||
| 23983 | + CHECK(try_catch.HasCaught()); | ||
| 23984 | + } | ||
| 23985 | + | ||
| 23954 | 23986 | TEST(SyntheticModuleEvaluationStepsNoThrow) { | |
| 23955 | 23987 | synthetic_module_callback_count = 0; | |
| 23956 | 23988 | LocalContext env; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments