| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9e9ac3c commit 3d957d1
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,6 @@ using v8::Context; | |||
| 20 | 20 | using v8::FunctionCallbackInfo; | |
| 21 | 21 | using v8::Isolate; | |
| 22 | 22 | using v8::Local; | |
| 23 | - using v8::MaybeLocal; | ||
| 24 | 23 | using v8::Object; | |
| 25 | 24 | using v8::ObjectTemplate; | |
| 26 | 25 | using v8::String; | |
@@ -139,8 +138,7 @@ void BindingData::EncodeUtf8String(const FunctionCallbackInfo<Value>& args) { | |||
| 139 | 138 | ab = ArrayBuffer::New(isolate, std::move(bs)); | |
| 140 | 139 | } | |
| 141 | 140 | ||
| 142 | - auto array = Uint8Array::New(ab, 0, length); | ||
| 143 | - args.GetReturnValue().Set(array); | ||
| 141 | + args.GetReturnValue().Set(Uint8Array::New(ab, 0, length)); | ||
| 144 | 142 | } | |
| 145 | 143 | ||
| 146 | 144 | // Convert the input into an encoded string | |
@@ -184,11 +182,10 @@ void BindingData::DecodeUTF8(const FunctionCallbackInfo<Value>& args) { | |||
| 184 | 182 | if (length == 0) return args.GetReturnValue().SetEmptyString(); | |
| 185 | 183 | ||
| 186 | 184 | Local<Value> error; | |
| 187 | - MaybeLocal<Value> maybe_ret = | ||
| 188 | - StringBytes::Encode(env->isolate(), data, length, UTF8, &error); | ||
| 189 | 185 | Local<Value> ret; | |
| 190 | 186 | ||
| 191 | - if (!maybe_ret.ToLocal(&ret)) { | ||
| 187 | + if (!StringBytes::Encode(env->isolate(), data, length, UTF8, &error) | ||
| 188 | + .ToLocal(&ret)) { | ||
| 192 | 189 | CHECK(!error.IsEmpty()); | |
| 193 | 190 | env->isolate()->ThrowException(error); | |
| 194 | 191 | return; | |
@@ -204,8 +201,10 @@ void BindingData::ToASCII(const v8::FunctionCallbackInfo<v8::Value>& args) { | |||
| 204 | 201 | ||
| 205 | 202 | Utf8Value input(env->isolate(), args[0]); | |
| 206 | 203 | auto out = ada::idna::to_ascii(input.ToStringView()); | |
| 207 | - args.GetReturnValue().Set( | ||
| 208 | - String::NewFromUtf8(env->isolate(), out.c_str()).ToLocalChecked()); | ||
| 204 | + Local<Value> ret; | ||
| 205 | + if (ToV8Value(env->context(), out, env->isolate()).ToLocal(&ret)) { | ||
| 206 | + args.GetReturnValue().Set(ret); | ||
| 207 | + } | ||
| 209 | 208 | } | |
| 210 | 209 | ||
| 211 | 210 | void BindingData::ToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
@@ -215,8 +214,10 @@ void BindingData::ToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args) { | |||
| 215 | 214 | ||
| 216 | 215 | Utf8Value input(env->isolate(), args[0]); | |
| 217 | 216 | auto out = ada::idna::to_unicode(input.ToStringView()); | |
| 218 | - args.GetReturnValue().Set( | ||
| 219 | - String::NewFromUtf8(env->isolate(), out.c_str()).ToLocalChecked()); | ||
| 217 | + Local<Value> ret; | ||
| 218 | + if (ToV8Value(env->context(), out, env->isolate()).ToLocal(&ret)) { | ||
| 219 | + args.GetReturnValue().Set(ret); | ||
| 220 | + } | ||
| 220 | 221 | } | |
| 221 | 222 | ||
| 222 | 223 | void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data, | |
@@ -286,11 +287,12 @@ void BindingData::DecodeLatin1(const FunctionCallbackInfo<Value>& args) { | |||
| 286 | 287 | env->isolate(), "The encoded data was not valid for encoding latin1"); | |
| 287 | 288 | } | |
| 288 | 289 | ||
| 289 | - Local<String> output = | ||
| 290 | - String::NewFromUtf8( | ||
| 291 | - env->isolate(), result.c_str(), v8::NewStringType::kNormal, written) | ||
| 292 | - .ToLocalChecked(); | ||
| 293 | - args.GetReturnValue().Set(output); | ||
| 290 | + std::string_view view(result.c_str(), written); | ||
| 291 | + | ||
| 292 | + Local<Value> ret; | ||
| 293 | + if (ToV8Value(env->context(), view, env->isolate()).ToLocal(&ret)) { | ||
| 294 | + args.GetReturnValue().Set(ret); | ||
| 295 | + } | ||
| 294 | 296 | } | |
| 295 | 297 | ||
| 296 | 298 | } // namespace encoding_binding | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,6 +51,7 @@ using v8::HandleScope; | |||
| 51 | 51 | using v8::Isolate; | |
| 52 | 52 | using v8::Local; | |
| 53 | 53 | using v8::Message; | |
| 54 | + using v8::Name; | ||
| 54 | 55 | using v8::Object; | |
| 55 | 56 | using v8::Value; | |
| 56 | 57 | using v8_inspector::StringBuffer; | |
@@ -411,12 +412,12 @@ class SameThreadInspectorSession : public InspectorSession { | |||
| 411 | 412 | void NotifyClusterWorkersDebugEnabled(Environment* env) { | |
| 412 | 413 | Isolate* isolate = env->isolate(); | |
| 413 | 414 | HandleScope handle_scope(isolate); | |
| 414 | - Local<Context> context = env->context(); | ||
| 415 | 415 | ||
| 416 | 416 | // Send message to enable debug in cluster workers | |
| 417 | - Local<Object> message = Object::New(isolate); | ||
| 418 | - message->Set(context, FIXED_ONE_BYTE_STRING(isolate, "cmd"), | ||
| 419 | - FIXED_ONE_BYTE_STRING(isolate, "NODE_DEBUG_ENABLED")).Check(); | ||
| 417 | + Local<Name> name = FIXED_ONE_BYTE_STRING(isolate, "cmd"); | ||
| 418 | + Local<Value> value = FIXED_ONE_BYTE_STRING(isolate, "NODE_DEBUG_ENABLED"); | ||
| 419 | + Local<Object> message = | ||
| 420 | + Object::New(isolate, Object::New(isolate), &name, &value, 1); | ||
| 420 | 421 | ProcessEmit(env, "internalMessage", message); | |
| 421 | 422 | } | |
| 422 | 423 | ||
@@ -441,11 +442,13 @@ bool IsFilePath(const std::string& path) { | |||
| 441 | 442 | void ThrowUninitializedInspectorError(Environment* env) { | |
| 442 | 443 | HandleScope scope(env->isolate()); | |
| 443 | 444 | ||
| 444 | - const char* msg = "This Environment was initialized without a V8::Inspector"; | ||
| 445 | - Local<Value> exception = | ||
| 446 | - v8::String::NewFromUtf8(env->isolate(), msg).ToLocalChecked(); | ||
| 447 | - | ||
| 448 | - env->isolate()->ThrowException(exception); | ||
| 445 | + std::string_view msg = | ||
| 446 | + "This Environment was initialized without a V8::Inspector"; | ||
| 447 | + Local<Value> exception; | ||
| 448 | + if (ToV8Value(env->context(), msg, env->isolate()).ToLocal(&exception)) { | ||
| 449 | + env->isolate()->ThrowException(exception); | ||
| 450 | + } | ||
| 451 | + // V8 will have scheduled a superseding error here. | ||
| 449 | 452 | } | |
| 450 | 453 | ||
| 451 | 454 | } // namespace | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -188,11 +188,12 @@ void CallAndPauseOnStart(const FunctionCallbackInfo<v8::Value>& args) { | |||
| 188 | 188 | CHECK(args[0]->IsFunction()); | |
| 189 | 189 | SlicedArguments call_args(args, /* start */ 2); | |
| 190 | 190 | env->inspector_agent()->PauseOnNextJavascriptStatement("Break on start"); | |
| 191 | - v8::MaybeLocal<v8::Value> retval = | ||
| 192 | - args[0].As<v8::Function>()->Call(env->context(), args[1], | ||
| 193 | - call_args.length(), call_args.out()); | ||
| 194 | - if (!retval.IsEmpty()) { | ||
| 195 | - args.GetReturnValue().Set(retval.ToLocalChecked()); | ||
| 191 | + Local<Value> ret; | ||
| 192 | + if (args[0] | ||
| 193 | + .As<v8::Function>() | ||
| 194 | + ->Call(env->context(), args[1], call_args.length(), call_args.out()) | ||
| 195 | + .ToLocal(&ret)) { | ||
| 196 | + args.GetReturnValue().Set(ret); | ||
| 196 | 197 | } | |
| 197 | 198 | } | |
| 198 | 199 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,7 +26,6 @@ using v8::Context; | |||
| 26 | 26 | using v8::FunctionCallbackInfo; | |
| 27 | 27 | using v8::Isolate; | |
| 28 | 28 | using v8::Local; | |
| 29 | - using v8::MaybeLocal; | ||
| 30 | 29 | using v8::Object; | |
| 31 | 30 | using v8::Uint32; | |
| 32 | 31 | using v8::Value; | |
@@ -111,9 +110,10 @@ static void SafeGetenv(const FunctionCallbackInfo<Value>& args) { | |||
| 111 | 110 | Utf8Value strenvtag(isolate, args[0]); | |
| 112 | 111 | std::string text; | |
| 113 | 112 | if (!SafeGetenv(*strenvtag, &text, env)) return; | |
| 114 | - Local<Value> result = | ||
| 115 | - ToV8Value(isolate->GetCurrentContext(), text).ToLocalChecked(); | ||
| 116 | - args.GetReturnValue().Set(result); | ||
| 113 | + Local<Value> result; | ||
| 114 | + if (ToV8Value(isolate->GetCurrentContext(), text).ToLocal(&result)) { | ||
| 115 | + args.GetReturnValue().Set(result); | ||
| 116 | + } | ||
| 117 | 117 | } | |
| 118 | 118 | ||
| 119 | 119 | static void GetTempDir(const FunctionCallbackInfo<Value>& args) { | |
@@ -137,8 +137,10 @@ static void GetTempDir(const FunctionCallbackInfo<Value>& args) { | |||
| 137 | 137 | dir.pop_back(); | |
| 138 | 138 | } | |
| 139 | 139 | ||
| 140 | - args.GetReturnValue().Set( | ||
| 141 | - ToV8Value(isolate->GetCurrentContext(), dir).ToLocalChecked()); | ||
| 140 | + Local<Value> result; | ||
| 141 | + if (ToV8Value(isolate->GetCurrentContext(), dir).ToLocal(&result)) { | ||
| 142 | + args.GetReturnValue().Set(result); | ||
| 143 | + } | ||
| 142 | 144 | } | |
| 143 | 145 | ||
| 144 | 146 | #ifdef NODE_IMPLEMENTS_POSIX_CREDENTIALS | |
@@ -385,9 +387,10 @@ static void GetGroups(const FunctionCallbackInfo<Value>& args) { | |||
| 385 | 387 | gid_t egid = getegid(); | |
| 386 | 388 | if (std::find(groups.begin(), groups.end(), egid) == groups.end()) | |
| 387 | 389 | groups.push_back(egid); | |
| 388 | - MaybeLocal<Value> array = ToV8Value(env->context(), groups); | ||
| 389 | - if (!array.IsEmpty()) | ||
| 390 | - args.GetReturnValue().Set(array.ToLocalChecked()); | ||
| 390 | + Local<Value> result; | ||
| 391 | + if (ToV8Value(env->context(), groups).ToLocal(&result)) { | ||
| 392 | + args.GetReturnValue().Set(result); | ||
| 393 | + } | ||
| 391 | 394 | } | |
| 392 | 395 | ||
| 393 | 396 | static void SetGroups(const FunctionCallbackInfo<Value>& args) { | |
@@ -403,8 +406,12 @@ static void SetGroups(const FunctionCallbackInfo<Value>& args) { | |||
| 403 | 406 | MaybeStackBuffer<gid_t, 64> groups(size); | |
| 404 | 407 | ||
| 405 | 408 | for (size_t i = 0; i < size; i++) { | |
| 406 | - gid_t gid = gid_by_name( | ||
| 407 | - env->isolate(), groups_list->Get(env->context(), i).ToLocalChecked()); | ||
| 409 | + Local<Value> val; | ||
| 410 | + if (!groups_list->Get(env->context(), i).ToLocal(&val)) { | ||
| 411 | + // V8 will have scheduled an error to be thrown. | ||
| 412 | + return; | ||
| 413 | + } | ||
| 414 | + gid_t gid = gid_by_name(env->isolate(), val); | ||
| 408 | 415 | ||
| 409 | 416 | if (gid == gid_not_found) { | |
| 410 | 417 | // Tells JS to throw ERR_INVALID_CREDENTIAL | |
| Back | FazBrowse Home | New Git URL |
0 commit comments