| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b09eda5 commit c4074e3
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,7 +38,7 @@ | |||
| 38 | 38 | ||
| 39 | 39 | # Reset this number to 0 on major V8 upgrades. | |
| 40 | 40 | # Increment by one for each non-official patch applied to deps/v8. | |
| 41 | - 'v8_embedder_string': '-node.22', | ||
| 41 | + 'v8_embedder_string': '-node.23', | ||
| 42 | 42 | ||
| 43 | 43 | ##### V8 defaults for Node.js ##### | |
| 44 | 44 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1473,11 +1473,19 @@ class V8_EXPORT Module { | |||
| 1473 | 1473 | /** | |
| 1474 | 1474 | * Set this module's exported value for the name export_name to the specified | |
| 1475 | 1475 | * export_value. This method must be called only on Modules created via | |
| 1476 | - * CreateSyntheticModule. export_name must be one of the export_names that | ||
| 1477 | - * were passed in that CreateSyntheticModule call. | ||
| 1478 | - */ | ||
| 1479 | - void SetSyntheticModuleExport(Local<String> export_name, | ||
| 1480 | - Local<Value> export_value); | ||
| 1476 | + * CreateSyntheticModule. An error will be thrown if export_name is not one | ||
| 1477 | + * of the export_names that were passed in that CreateSyntheticModule call. | ||
| 1478 | + * Returns Just(true) on success, Nothing<bool>() if an error was thrown. | ||
| 1479 | + */ | ||
| 1480 | + V8_WARN_UNUSED_RESULT Maybe<bool> SetSyntheticModuleExport( | ||
| 1481 | + Isolate* isolate, Local<String> export_name, Local<Value> export_value); | ||
| 1482 | + V8_DEPRECATE_SOON( | ||
| 1483 | + "Use the preceding SetSyntheticModuleExport with an Isolate parameter, " | ||
| 1484 | + "instead of the one that follows. The former will throw a runtime " | ||
| 1485 | + "error if called for an export that doesn't exist (as per spec); " | ||
| 1486 | + "the latter will crash with a failed CHECK().", | ||
| 1487 | + void SetSyntheticModuleExport(Local<String> export_name, | ||
| 1488 | + Local<Value> export_value)); | ||
| 1481 | 1489 | }; | |
| 1482 | 1490 | ||
| 1483 | 1491 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2351,6 +2351,28 @@ Local<Module> Module::CreateSyntheticModule( | |||
| 2351 | 2351 | i_module_name, i_export_names, evaluation_steps))); | |
| 2352 | 2352 | } | |
| 2353 | 2353 | ||
| 2354 | + Maybe<bool> Module::SetSyntheticModuleExport(Isolate* isolate, | ||
| 2355 | + Local<String> export_name, | ||
| 2356 | + Local<v8::Value> export_value) { | ||
| 2357 | + auto i_isolate = reinterpret_cast<i::Isolate*>(isolate); | ||
| 2358 | + i::Handle<i::String> i_export_name = Utils::OpenHandle(*export_name); | ||
| 2359 | + i::Handle<i::Object> i_export_value = Utils::OpenHandle(*export_value); | ||
| 2360 | + i::Handle<i::Module> self = Utils::OpenHandle(this); | ||
| 2361 | + Utils::ApiCheck(self->IsSyntheticModule(), | ||
| 2362 | + "v8::Module::SyntheticModuleSetExport", | ||
| 2363 | + "v8::Module::SyntheticModuleSetExport must only be called on " | ||
| 2364 | + "a SyntheticModule"); | ||
| 2365 | + ENTER_V8_NO_SCRIPT(i_isolate, isolate->GetCurrentContext(), Module, | ||
| 2366 | + SetSyntheticModuleExport, Nothing<bool>(), i::HandleScope); | ||
| 2367 | + has_pending_exception = | ||
| 2368 | + i::SyntheticModule::SetExport(i_isolate, | ||
| 2369 | + i::Handle<i::SyntheticModule>::cast(self), | ||
| 2370 | + i_export_name, i_export_value) | ||
| 2371 | + .IsNothing(); | ||
| 2372 | + RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | ||
| 2373 | + return Just(true); | ||
| 2374 | + } | ||
| 2375 | + | ||
| 2354 | 2376 | void Module::SetSyntheticModuleExport(Local<String> export_name, | |
| 2355 | 2377 | Local<v8::Value> export_value) { | |
| 2356 | 2378 | i::Handle<i::String> i_export_name = Utils::OpenHandle(*export_name); | |
@@ -2360,9 +2382,9 @@ void Module::SetSyntheticModuleExport(Local<String> export_name, | |||
| 2360 | 2382 | "v8::Module::SetSyntheticModuleExport", | |
| 2361 | 2383 | "v8::Module::SetSyntheticModuleExport must only be called on " | |
| 2362 | 2384 | "a SyntheticModule"); | |
| 2363 | - i::SyntheticModule::SetExport(self->GetIsolate(), | ||
| 2364 | - i::Handle<i::SyntheticModule>::cast(self), | ||
| 2365 | - i_export_name, i_export_value); | ||
| 2385 | + i::SyntheticModule::SetExportStrict(self->GetIsolate(), | ||
| 2386 | + i::Handle<i::SyntheticModule>::cast(self), | ||
| 2387 | + i_export_name, i_export_value); | ||
| 2366 | 2388 | } | |
| 2367 | 2389 | ||
| 2368 | 2390 | namespace { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -780,6 +780,7 @@ class RuntimeCallTimer final { | |||
| 780 | 780 | V(Message_GetStartColumn) \ | |
| 781 | 781 | V(Module_Evaluate) \ | |
| 782 | 782 | V(Module_InstantiateModule) \ | |
| 783 | + V(Module_SetSyntheticModuleExport) \ | ||
| 783 | 784 | V(NumberObject_New) \ | |
| 784 | 785 | V(NumberObject_NumberValue) \ | |
| 785 | 786 | 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 | |
|---|---|---|---|
@@ -23693,7 +23693,9 @@ v8::MaybeLocal<Value> SyntheticModuleEvaluationStepsCallbackFail( | |||
| 23693 | 23693 | ||
| 23694 | 23694 | v8::MaybeLocal<Value> SyntheticModuleEvaluationStepsCallbackSetExport( | |
| 23695 | 23695 | Local<Context> context, Local<Module> module) { | |
| 23696 | - module->SetSyntheticModuleExport(v8_str("test_export"), v8_num(42)); | ||
| 23696 | + Maybe<bool> set_export_result = module->SetSyntheticModuleExport( | ||
| 23697 | + context->GetIsolate(), v8_str("test_export"), v8_num(42)); | ||
| 23698 | + CHECK(set_export_result.FromJust()); | ||
| 23697 | 23699 | return v8::Undefined(reinterpret_cast<v8::Isolate*>(context->GetIsolate())); | |
| 23698 | 23700 | } | |
| 23699 | 23701 | ||
@@ -23900,7 +23902,9 @@ TEST(SyntheticModuleSetExports) { | |||
| 23900 | 23902 | // undefined. | |
| 23901 | 23903 | CHECK(foo_cell->value().IsUndefined()); | |
| 23902 | 23904 | ||
| 23903 | - module->SetSyntheticModuleExport(foo_string, bar_string); | ||
| 23905 | + Maybe<bool> set_export_result = | ||
| 23906 | + module->SetSyntheticModuleExport(isolate, foo_string, bar_string); | ||
| 23907 | + CHECK(set_export_result.FromJust()); | ||
| 23904 | 23908 | ||
| 23905 | 23909 | // After setting the export the Cell should still have the same idenitity. | |
| 23906 | 23910 | CHECK_EQ(exports->Lookup(v8::Utils::OpenHandle(*foo_string)), *foo_cell); | |
@@ -23911,6 +23915,34 @@ TEST(SyntheticModuleSetExports) { | |||
| 23911 | 23915 | ->Equals(*v8::Utils::OpenHandle(*bar_string))); | |
| 23912 | 23916 | } | |
| 23913 | 23917 | ||
| 23918 | + TEST(SyntheticModuleSetMissingExport) { | ||
| 23919 | + LocalContext env; | ||
| 23920 | + v8::Isolate* isolate = env->GetIsolate(); | ||
| 23921 | + auto i_isolate = reinterpret_cast<i::Isolate*>(isolate); | ||
| 23922 | + v8::Isolate::Scope iscope(isolate); | ||
| 23923 | + v8::HandleScope scope(isolate); | ||
| 23924 | + v8::Local<v8::Context> context = v8::Context::New(isolate); | ||
| 23925 | + v8::Context::Scope cscope(context); | ||
| 23926 | + | ||
| 23927 | + Local<String> foo_string = v8_str("foo"); | ||
| 23928 | + Local<String> bar_string = v8_str("bar"); | ||
| 23929 | + | ||
| 23930 | + Local<Module> module = CreateAndInstantiateSyntheticModule( | ||
| 23931 | + isolate, v8_str("SyntheticModuleSetExports-TestSyntheticModule"), context, | ||
| 23932 | + std::vector<v8::Local<v8::String>>(), | ||
| 23933 | + UnexpectedSyntheticModuleEvaluationStepsCallback); | ||
| 23934 | + | ||
| 23935 | + i::Handle<i::SyntheticModule> i_module = | ||
| 23936 | + i::Handle<i::SyntheticModule>::cast(v8::Utils::OpenHandle(*module)); | ||
| 23937 | + i::Handle<i::ObjectHashTable> exports(i_module->exports(), i_isolate); | ||
| 23938 | + | ||
| 23939 | + TryCatch try_catch(isolate); | ||
| 23940 | + Maybe<bool> set_export_result = | ||
| 23941 | + module->SetSyntheticModuleExport(isolate, foo_string, bar_string); | ||
| 23942 | + CHECK(set_export_result.IsNothing()); | ||
| 23943 | + CHECK(try_catch.HasCaught()); | ||
| 23944 | + } | ||
| 23945 | + | ||
| 23914 | 23946 | TEST(SyntheticModuleEvaluationStepsNoThrow) { | |
| 23915 | 23947 | synthetic_module_callback_count = 0; | |
| 23916 | 23948 | LocalContext env; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments