@@ -22,17 +22,6 @@ using v8::SideEffectType;
2222using v8::String;
2323using v8::Value;
2424
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-
3625bool NativeModuleEnv::Add (const char * id, const UnionBytes& source) {
3726 return NativeModuleLoader::GetInstance ()->Add (id, source);
3827}
@@ -67,16 +56,26 @@ void NativeModuleEnv::GetModuleCategories(
6756 cannot_be_required.insert (" trace_events" );
6857 }
6958
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
7165 ->Set (context,
7266 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
7673 ->Set (context,
7774 OneByteString (isolate, " canBeRequired" ),
78- ToJsSet (context, can_be_required))
79- .FromJust ();
75+ can_be_required_js)
76+ .IsNothing ()) {
77+ return ;
78+ }
8079 info.GetReturnValue ().Set (result);
8180}
8281
@@ -85,23 +84,45 @@ void NativeModuleEnv::GetCacheUsage(const FunctionCallbackInfo<Value>& args) {
8584 Isolate* isolate = env->isolate ();
8685 Local<Context> context = env->context ();
8786 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
8996 ->Set (env->context (),
9097 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
94108 ->Set (env->context (),
95109 OneByteString (isolate, " compiledWithoutCache" ),
96- ToJsSet (context, env->native_modules_without_cache ))
97- .FromJust ();
110+ native_modules_without_cache_js)
111+ .IsNothing ()) {
112+ return ;
113+ }
98114
99- result
115+ if (!ToV8Value (context, env->native_modules_in_snapshot )
116+ .ToLocal (&native_modules_without_cache_js)) {
117+ return ;
118+ }
119+ if (result
100120 ->Set (env->context (),
101121 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+ }
105126
106127 args.GetReturnValue ().Set (result);
107128}
0 commit comments