@@ -111,9 +111,8 @@ using v8::Value;
111
111
namespace {
112
112
113
113
// Convert an int to a V8 Name (String or Symbol).
114
- Local<Name> Uint32ToName (Local<Context> context, uint32_t index) {
115
- return Uint32::New (context->GetIsolate (), index)->ToString (context)
116
- .ToLocalChecked ();
114
+ MaybeLocal<String> Uint32ToName (Local<Context> context, uint32_t index) {
115
+ return Uint32::New (context->GetIsolate (), index)->ToString (context);
117
116
}
118
117
119
118
} // anonymous namespace
@@ -852,8 +851,11 @@ Intercepted ContextifyContext::IndexedPropertyQueryCallback(
852
851
return Intercepted::kNo ;
853
852
}
854
853
855
- return ContextifyContext::PropertyQueryCallback (
856
- Uint32ToName (ctx->context (), index), args);
854
+ Local<String> name;
855
+ if (Uint32ToName (ctx->context (), index).ToLocal (&name)) {
856
+ return ContextifyContext::PropertyQueryCallback (name, args);
857
+ }
858
+ return Intercepted::kNo ;
857
859
}
858
860
859
861
// static
@@ -866,8 +868,11 @@ Intercepted ContextifyContext::IndexedPropertyGetterCallback(
866
868
return Intercepted::kNo ;
867
869
}
868
870
869
- return ContextifyContext::PropertyGetterCallback (
870
- Uint32ToName (ctx->context (), index), args);
871
+ Local<String> name;
872
+ if (Uint32ToName (ctx->context (), index).ToLocal (&name)) {
873
+ return ContextifyContext::PropertyGetterCallback (name, args);
874
+ }
875
+ return Intercepted::kNo ;
871
876
}
872
877
873
878
Intercepted ContextifyContext::IndexedPropertySetterCallback (
@@ -881,8 +886,11 @@ Intercepted ContextifyContext::IndexedPropertySetterCallback(
881
886
return Intercepted::kNo ;
882
887
}
883
888
884
- return ContextifyContext::PropertySetterCallback (
885
- Uint32ToName (ctx->context (), index), value, args);
889
+ Local<String> name;
890
+ if (Uint32ToName (ctx->context (), index).ToLocal (&name)) {
891
+ return ContextifyContext::PropertySetterCallback (name, value, args);
892
+ }
893
+ return Intercepted::kNo ;
886
894
}
887
895
888
896
// static
@@ -895,8 +903,11 @@ Intercepted ContextifyContext::IndexedPropertyDescriptorCallback(
895
903
return Intercepted::kNo ;
896
904
}
897
905
898
- return ContextifyContext::PropertyDescriptorCallback (
899
- Uint32ToName (ctx->context (), index), args);
906
+ Local<String> name;
907
+ if (Uint32ToName (ctx->context (), index).ToLocal (&name)) {
908
+ return ContextifyContext::PropertyDescriptorCallback (name, args);
909
+ }
910
+ return Intercepted::kNo ;
900
911
}
901
912
902
913
Intercepted ContextifyContext::IndexedPropertyDefinerCallback (
@@ -910,8 +921,11 @@ Intercepted ContextifyContext::IndexedPropertyDefinerCallback(
910
921
return Intercepted::kNo ;
911
922
}
912
923
913
- return ContextifyContext::PropertyDefinerCallback (
914
- Uint32ToName (ctx->context (), index), desc, args);
924
+ Local<String> name;
925
+ if (Uint32ToName (ctx->context (), index).ToLocal (&name)) {
926
+ return ContextifyContext::PropertyDefinerCallback (name, desc, args);
927
+ }
928
+ return Intercepted::kNo ;
915
929
}
916
930
917
931
// static
@@ -1130,22 +1144,20 @@ Maybe<void> StoreCodeCacheResult(
1130
1144
if (produce_cached_data) {
1131
1145
bool cached_data_produced = new_cached_data != nullptr ;
1132
1146
if (cached_data_produced) {
1133
- MaybeLocal<Object> buf =
1134
- Buffer::Copy (env,
1135
- reinterpret_cast <const char *>(new_cached_data->data ),
1136
- new_cached_data->length );
1137
- if (target->Set (context, env->cached_data_string (), buf.ToLocalChecked ())
1147
+ Local<Object> buf;
1148
+ if (!Buffer::Copy (env,
1149
+ reinterpret_cast <const char *>(new_cached_data->data ),
1150
+ new_cached_data->length )
1151
+ .ToLocal (&buf) ||
1152
+ target->Set (context, env->cached_data_string (), buf).IsNothing () ||
1153
+ target
1154
+ ->Set (context,
1155
+ env->cached_data_produced_string (),
1156
+ Boolean::New (env->isolate (), cached_data_produced))
1138
1157
.IsNothing ()) {
1139
1158
return Nothing<void >();
1140
1159
}
1141
1160
}
1142
- if (target
1143
- ->Set (context,
1144
- env->cached_data_produced_string (),
1145
- Boolean::New (env->isolate (), cached_data_produced))
1146
- .IsNothing ()) {
1147
- return Nothing<void >();
1148
- }
1149
1161
}
1150
1162
return JustVoid ();
1151
1163
}
@@ -1179,14 +1191,19 @@ void ContextifyScript::CreateCachedData(
1179
1191
ASSIGN_OR_RETURN_UNWRAP_CPPGC (&wrapped_script, args.This ());
1180
1192
std::unique_ptr<ScriptCompiler::CachedData> cached_data (
1181
1193
ScriptCompiler::CreateCodeCache (wrapped_script->unbound_script ()));
1182
- if (!cached_data) {
1183
- args.GetReturnValue ().Set (Buffer::New (env, 0 ).ToLocalChecked ());
1184
- } else {
1185
- MaybeLocal<Object> buf = Buffer::Copy (
1186
- env,
1187
- reinterpret_cast <const char *>(cached_data->data ),
1188
- cached_data->length );
1189
- args.GetReturnValue ().Set (buf.ToLocalChecked ());
1194
+
1195
+ auto maybeRet = ([&] {
1196
+ if (!cached_data) {
1197
+ return Buffer::New (env, 0 );
1198
+ }
1199
+ return Buffer::Copy (env,
1200
+ reinterpret_cast <const char *>(cached_data->data ),
1201
+ cached_data->length );
1202
+ })();
1203
+
1204
+ Local<Object> ret;
1205
+ if (maybeRet.ToLocal (&ret)) {
1206
+ args.GetReturnValue ().Set (ret);
1190
1207
}
1191
1208
}
1192
1209
0 commit comments