@@ -22,17 +22,6 @@ using v8::SideEffectType;
22
22
using v8::String;
23
23
using v8::Value;
24
24
25
- // TODO(joyeecheung): make these more general and put them into util.h
26
- Local<Set> ToJsSet (Local<Context> context, const std::set<std::string>& in) {
27
- Isolate* isolate = context->GetIsolate ();
28
- Local<Set> out = Set::New (isolate);
29
- for (auto const & x : in) {
30
- out->Add (context, OneByteString (isolate, x.c_str (), x.size ()))
31
- .ToLocalChecked ();
32
- }
33
- return out;
34
- }
35
-
36
25
bool NativeModuleEnv::Add (const char * id, const UnionBytes& source) {
37
26
return NativeModuleLoader::GetInstance ()->Add (id, source);
38
27
}
@@ -67,16 +56,26 @@ void NativeModuleEnv::GetModuleCategories(
67
56
cannot_be_required.insert (" trace_events" );
68
57
}
69
58
70
- result
59
+ Local<Value> cannot_be_required_js;
60
+ Local<Value> can_be_required_js;
61
+
62
+ if (!ToV8Value (context, cannot_be_required).ToLocal (&cannot_be_required_js))
63
+ return ;
64
+ if (result
71
65
->Set (context,
72
66
OneByteString (isolate, " cannotBeRequired" ),
73
- ToJsSet (context, cannot_be_required))
74
- .FromJust ();
75
- result
67
+ cannot_be_required_js)
68
+ .IsNothing ())
69
+ return ;
70
+ if (!ToV8Value (context, can_be_required).ToLocal (&can_be_required_js))
71
+ return ;
72
+ if (result
76
73
->Set (context,
77
74
OneByteString (isolate, " canBeRequired" ),
78
- ToJsSet (context, can_be_required))
79
- .FromJust ();
75
+ can_be_required_js)
76
+ .IsNothing ()) {
77
+ return ;
78
+ }
80
79
info.GetReturnValue ().Set (result);
81
80
}
82
81
@@ -85,23 +84,45 @@ void NativeModuleEnv::GetCacheUsage(const FunctionCallbackInfo<Value>& args) {
85
84
Isolate* isolate = env->isolate ();
86
85
Local<Context> context = env->context ();
87
86
Local<Object> result = Object::New (isolate);
88
- result
87
+
88
+ Local<Value> native_modules_with_cache_js;
89
+ Local<Value> native_modules_without_cache_js;
90
+ Local<Value> native_modules_in_snapshot_js;
91
+ if (!ToV8Value (context, env->native_modules_with_cache )
92
+ .ToLocal (&native_modules_with_cache_js)) {
93
+ return ;
94
+ }
95
+ if (result
89
96
->Set (env->context (),
90
97
OneByteString (isolate, " compiledWithCache" ),
91
- ToJsSet (context, env->native_modules_with_cache ))
92
- .FromJust ();
93
- result
98
+ native_modules_with_cache_js)
99
+ .IsNothing ()) {
100
+ return ;
101
+ }
102
+
103
+ if (!ToV8Value (context, env->native_modules_without_cache )
104
+ .ToLocal (&native_modules_without_cache_js)) {
105
+ return ;
106
+ }
107
+ if (result
94
108
->Set (env->context (),
95
109
OneByteString (isolate, " compiledWithoutCache" ),
96
- ToJsSet (context, env->native_modules_without_cache ))
97
- .FromJust ();
110
+ native_modules_without_cache_js)
111
+ .IsNothing ()) {
112
+ return ;
113
+ }
98
114
99
- result
115
+ if (!ToV8Value (context, env->native_modules_in_snapshot )
116
+ .ToLocal (&native_modules_without_cache_js)) {
117
+ return ;
118
+ }
119
+ if (result
100
120
->Set (env->context (),
101
121
OneByteString (isolate, " compiledInSnapshot" ),
102
- ToV8Value (env->context (), env->native_modules_in_snapshot )
103
- .ToLocalChecked ())
104
- .FromJust ();
122
+ native_modules_without_cache_js)
123
+ .IsNothing ()) {
124
+ return ;
125
+ }
105
126
106
127
args.GetReturnValue ().Set (result);
107
128
}
0 commit comments