GeezerVison is showing github.com — src: add IsolateScopes before using isolates · nodejs/node@faf6a04
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/api/environment.cc +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -313,6 +313,8 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) { | 313 | 313 |
| 314 | 314 | void SetIsolateUpForNode(v8::Isolate* isolate, | 315 | 315 | const IsolateSettings& settings) { | | 316 | + Isolate::Scope isolate_scope(isolate); | | 317 | + | 316 | 318 | SetIsolateErrorHandlers(isolate, settings); | 317 | 319 | SetIsolateMiscHandlers(isolate, settings); | 318 | 320 | } | @@ -354,6 +356,9 @@ Isolate* NewIsolate(Isolate::CreateParams* params, | 354 | 356 |
| 355 | 357 | SetIsolateCreateParamsForNode(params); | 356 | 358 | Isolate::Initialize(isolate, *params); | | 359 | + | | 360 | + Isolate::Scope isolate_scope(isolate); | | 361 | + | 357 | 362 | if (snapshot_data == nullptr) { | 358 | 363 | // If in deserialize mode, delay until after the deserialization is | 359 | 364 | // complete. | @@ -428,6 +433,8 @@ Environment* CreateEnvironment( | 428 | 433 | ThreadId thread_id, | 429 | 434 | std::unique_ptr<InspectorParentHandle> inspector_parent_handle) { | 430 | 435 | Isolate* isolate = isolate_data->isolate(); | | 436 | + | | 437 | + Isolate::Scope isolate_scope(isolate); | 431 | 438 | HandleScope handle_scope(isolate); | 432 | 439 |
| 433 | 440 | const bool use_snapshot = context.IsEmpty(); | |
Collapse file Copy file name to clipboardExpand all lines: src/env.cc +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -349,6 +349,8 @@ IsolateDataSerializeInfo IsolateData::Serialize(SnapshotCreator* creator) { | 349 | 349 |
| 350 | 350 | void IsolateData::DeserializeProperties(const IsolateDataSerializeInfo* info) { | 351 | 351 | size_t i = 0; | | 352 | + | | 353 | + v8::Isolate::Scope isolate_scope(isolate_); | 352 | 354 | HandleScope handle_scope(isolate_); | 353 | 355 |
| 354 | 356 | if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) { | @@ -431,6 +433,7 @@ void IsolateData::CreateProperties() { | 431 | 433 | // One byte because our strings are ASCII and we can safely skip V8's UTF-8 | 432 | 434 | // decoding step. | 433 | 435 |
| | 436 | + v8::Isolate::Scope isolate_scope(isolate_); | 434 | 437 | HandleScope handle_scope(isolate_); | 435 | 438 |
| 436 | 439 | #define V(PropertyName, StringValue) \ | |
Collapse file Copy file name to clipboardExpand all lines: src/json_parser.cc +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,6 +17,7 @@ bool JSONParser::Parse(const std::string& content) { | 17 | 17 | DCHECK(!parsed_); | 18 | 18 |
| 19 | 19 | Isolate* isolate = isolate_.get(); | | 20 | + v8::Isolate::Scope isolate_scope(isolate); | 20 | 21 | v8::HandleScope handle_scope(isolate); | 21 | 22 |
| 22 | 23 | Local<Context> context = Context::New(isolate); | @@ -45,6 +46,7 @@ bool JSONParser::Parse(const std::string& content) { | 45 | 46 | std::optional<std::string> JSONParser::GetTopLevelStringField( | 46 | 47 | std::string_view field) { | 47 | 48 | Isolate* isolate = isolate_.get(); | | 49 | + v8::Isolate::Scope isolate_scope(isolate); | 48 | 50 | v8::HandleScope handle_scope(isolate); | 49 | 51 |
| 50 | 52 | Local<Context> context = context_.Get(isolate); | @@ -70,6 +72,7 @@ std::optional<std::string> JSONParser::GetTopLevelStringField( | 70 | 72 |
| 71 | 73 | std::optional<bool> JSONParser::GetTopLevelBoolField(std::string_view field) { | 72 | 74 | Isolate* isolate = isolate_.get(); | | 75 | + v8::Isolate::Scope isolate_scope(isolate); | 73 | 76 | v8::HandleScope handle_scope(isolate); | 74 | 77 |
| 75 | 78 | Local<Context> context = context_.Get(isolate); | |
Collapse file Copy file name to clipboardExpand all lines: src/json_parser.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,7 +24,7 @@ class JSONParser { | 24 | 24 | private: | 25 | 25 | // We might want a lighter-weight JSON parser for this use case. But for now | 26 | 26 | // using V8 is good enough. | 27 | | - RAIIIsolate isolate_; | | 27 | + RAIIIsolateWithoutEntering isolate_; | 28 | 28 |
| 29 | 29 | v8::Global<v8::Context> context_; | 30 | 30 | v8::Global<v8::Object> content_; | |
Collapse file Copy file name to clipboardExpand all lines: src/node_sea.cc +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -414,7 +414,9 @@ std::optional<std::string> GenerateCodeCache(std::string_view main_path, | 414 | 414 | RAIIIsolate raii_isolate(SnapshotBuilder::GetEmbeddedSnapshotData()); | 415 | 415 | Isolate* isolate = raii_isolate.get(); | 416 | 416 |
| | 417 | + v8::Isolate::Scope isolate_scope(isolate); | 417 | 418 | HandleScope handle_scope(isolate); | | 419 | + | 418 | 420 | Local<Context> context = Context::New(isolate); | 419 | 421 | Context::Scope context_scope(context); | 420 | 422 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/util.cc +7-2Lines changed: 7 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -678,7 +678,7 @@ Local<String> UnionBytes::ToStringChecked(Isolate* isolate) const { | 678 | 678 | } | 679 | 679 | } | 680 | 680 |
| 681 | | -RAIIIsolate::RAIIIsolate(const SnapshotData* data) | | 681 | +RAIIIsolateWithoutEntering::RAIIIsolateWithoutEntering(const SnapshotData* data) | 682 | 682 | : allocator_{ArrayBuffer::Allocator::NewDefaultAllocator()} { | 683 | 683 | isolate_ = Isolate::Allocate(); | 684 | 684 | CHECK_NOT_NULL(isolate_); | @@ -692,9 +692,14 @@ RAIIIsolate::RAIIIsolate(const SnapshotData* data) | 692 | 692 | Isolate::Initialize(isolate_, params); | 693 | 693 | } | 694 | 694 |
| 695 | | -RAIIIsolate::~RAIIIsolate() { | | 695 | +RAIIIsolateWithoutEntering::~RAIIIsolateWithoutEntering() { | 696 | 696 | per_process::v8_platform.Platform()->UnregisterIsolate(isolate_); | 697 | 697 | isolate_->Dispose(); | 698 | 698 | } | 699 | 699 |
| | 700 | +RAIIIsolate::RAIIIsolate(const SnapshotData* data) | | 701 | + : isolate_{data}, isolate_scope_{isolate_.get()} {} | | 702 | + | | 703 | +RAIIIsolate::~RAIIIsolate() {} | | 704 | + | 700 | 705 | } // namespace node |
Collapse file Copy file name to clipboardExpand all lines: src/util.h +18-4Lines changed: 18 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -969,11 +969,11 @@ void SetConstructorFunction(v8::Isolate* isolate, | 969 | 969 | SetConstructorFunctionFlag flag = | 970 | 970 | SetConstructorFunctionFlag::SET_CLASS_NAME); | 971 | 971 |
| 972 | | -// Simple RAII class to spin up a v8::Isolate instance. | 973 | | -class RAIIIsolate { | | 972 | +// Like RAIIIsolate, except doesn't enter the isolate while it's in scope. | | 973 | +class RAIIIsolateWithoutEntering { | 974 | 974 | public: | 975 | | - explicit RAIIIsolate(const SnapshotData* data = nullptr); | 976 | | - ~RAIIIsolate(); | | 975 | + explicit RAIIIsolateWithoutEntering(const SnapshotData* data = nullptr); | | 976 | + ~RAIIIsolateWithoutEntering(); | 977 | 977 |
| 978 | 978 | v8::Isolate* get() const { return isolate_; } | 979 | 979 |
| @@ -982,6 +982,20 @@ class RAIIIsolate { | 982 | 982 | v8::Isolate* isolate_; | 983 | 983 | }; | 984 | 984 |
| | 985 | +// Simple RAII class to spin up a v8::Isolate instance and enter it | | 986 | +// immediately. | | 987 | +class RAIIIsolate { | | 988 | + public: | | 989 | + explicit RAIIIsolate(const SnapshotData* data = nullptr); | | 990 | + ~RAIIIsolate(); | | 991 | + | | 992 | + v8::Isolate* get() const { return isolate_.get(); } | | 993 | + | | 994 | + private: | | 995 | + RAIIIsolateWithoutEntering isolate_; | | 996 | + v8::Isolate::Scope isolate_scope_; | | 997 | +}; | | 998 | + | 985 | 999 | } // namespace node | 986 | 1000 |
| 987 | 1001 | #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
|