@@ -111,9 +111,8 @@ using v8::Value;
111111namespace {
112112
113113// 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);
117116}
118117
119118} // anonymous namespace
@@ -852,8 +851,11 @@ Intercepted ContextifyContext::IndexedPropertyQueryCallback(
852851 return Intercepted::kNo ;
853852 }
854853
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 ;
857859}
858860
859861// static
@@ -866,8 +868,11 @@ Intercepted ContextifyContext::IndexedPropertyGetterCallback(
866868 return Intercepted::kNo ;
867869 }
868870
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 ;
871876}
872877
873878Intercepted ContextifyContext::IndexedPropertySetterCallback (
@@ -881,8 +886,11 @@ Intercepted ContextifyContext::IndexedPropertySetterCallback(
881886 return Intercepted::kNo ;
882887 }
883888
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 ;
886894}
887895
888896// static
@@ -895,8 +903,11 @@ Intercepted ContextifyContext::IndexedPropertyDescriptorCallback(
895903 return Intercepted::kNo ;
896904 }
897905
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 ;
900911}
901912
902913Intercepted ContextifyContext::IndexedPropertyDefinerCallback (
@@ -910,8 +921,11 @@ Intercepted ContextifyContext::IndexedPropertyDefinerCallback(
910921 return Intercepted::kNo ;
911922 }
912923
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 ;
915929}
916930
917931// static
@@ -1130,22 +1144,20 @@ Maybe<void> StoreCodeCacheResult(
11301144 if (produce_cached_data) {
11311145 bool cached_data_produced = new_cached_data != nullptr ;
11321146 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))
11381157 .IsNothing ()) {
11391158 return Nothing<void >();
11401159 }
11411160 }
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- }
11491161 }
11501162 return JustVoid ();
11511163}
@@ -1179,14 +1191,19 @@ void ContextifyScript::CreateCachedData(
11791191 ASSIGN_OR_RETURN_UNWRAP_CPPGC (&wrapped_script, args.This ());
11801192 std::unique_ptr<ScriptCompiler::CachedData> cached_data (
11811193 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);
11901207 }
11911208}
11921209
0 commit comments