@@ -11,16 +11,16 @@ using v8::Object; |
11 | 11 | using v8::String; |
12 | 12 | using v8::Value; |
13 | 13 |
|
14 | | -JSONParser::JSONParser() |
15 | | - : handle_scope_(isolate_.get()), |
16 | | - context_(isolate_.get(), Context::New(isolate_.get())), |
17 | | - context_scope_(context_.Get(isolate_.get())) {} |
| 14 | +JSONParser::JSONParser() {} |
18 | 15 |
|
19 | 16 | bool JSONParser::Parse(const std::string& content) { |
20 | 17 | DCHECK(!parsed_); |
21 | 18 |
|
22 | 19 | Isolate* isolate = isolate_.get(); |
23 | | - Local<Context> context = context_.Get(isolate); |
| 20 | + v8::HandleScope handle_scope(isolate); |
| 21 | + |
| 22 | + Local<Context> context = Context::New(isolate); |
| 23 | + Context::Scope context_scope(context); |
24 | 24 |
|
25 | 25 | // It's not a real script, so don't print the source line. |
26 | 26 | errors::PrinterTryCatch bootstrapCatch( |
@@ -34,16 +34,24 @@ bool JSONParser::Parse(const std::string& content) { |
34 | 34 | !result_value->IsObject()) { |
35 | 35 | return false; |
36 | 36 | } |
| 37 | + |
| 38 | + context_.Reset(isolate, context); |
37 | 39 | content_.Reset(isolate, result_value.As<Object>()); |
38 | 40 | parsed_ = true; |
| 41 | + |
39 | 42 | return true; |
40 | 43 | } |
41 | 44 |
|
42 | 45 | std::optional<std::string> JSONParser::GetTopLevelStringField( |
43 | 46 | std::string_view field) { |
44 | 47 | Isolate* isolate = isolate_.get(); |
| 48 | + v8::HandleScope handle_scope(isolate); |
| 49 | + |
45 | 50 | Local<Context> context = context_.Get(isolate); |
| 51 | + Context::Scope context_scope(context); |
| 52 | + |
46 | 53 | Local<Object> content_object = content_.Get(isolate); |
| 54 | + |
47 | 55 | Local<Value> value; |
48 | 56 | // It's not a real script, so don't print the source line. |
49 | 57 | errors::PrinterTryCatch bootstrapCatch( |
@@ -62,7 +70,11 @@ std::optional<std::string> JSONParser::GetTopLevelStringField( |
62 | 70 |
|
63 | 71 | std::optional<bool> JSONParser::GetTopLevelBoolField(std::string_view field) { |
64 | 72 | Isolate* isolate = isolate_.get(); |
| 73 | + v8::HandleScope handle_scope(isolate); |
| 74 | + |
65 | 75 | Local<Context> context = context_.Get(isolate); |
| 76 | + Context::Scope context_scope(context); |
| 77 | + |
66 | 78 | Local<Object> content_object = content_.Get(isolate); |
67 | 79 | Local<Value> value; |
68 | 80 | bool has_field; |
|