mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
src: improve error handling in multiple files
PR-URL: https://github.com/nodejs/node/pull/56962 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
@@ -104,14 +104,15 @@ namespace {
|
||||
|
||||
template <typename T>
|
||||
MaybeLocal<Object> ToBufferEndian(Environment* env, MaybeStackBuffer<T>* buf) {
|
||||
MaybeLocal<Object> ret = Buffer::New(env, buf);
|
||||
if (ret.IsEmpty())
|
||||
return ret;
|
||||
Local<Object> ret;
|
||||
if (!Buffer::New(env, buf).ToLocal(&ret)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
static_assert(sizeof(T) == 1 || sizeof(T) == 2,
|
||||
"Currently only one- or two-byte buffers are supported");
|
||||
if constexpr (sizeof(T) > 1 && IsBigEndian()) {
|
||||
SPREAD_BUFFER_ARG(ret.ToLocalChecked(), retbuf);
|
||||
SPREAD_BUFFER_ARG(ret, retbuf);
|
||||
CHECK(nbytes::SwapBytes16(retbuf_data, retbuf_length));
|
||||
}
|
||||
|
||||
@@ -317,19 +318,22 @@ void Transcode(const FunctionCallbackInfo<Value>&args) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
}
|
||||
|
||||
if (result.IsEmpty())
|
||||
return args.GetReturnValue().Set(status);
|
||||
Local<Object> res;
|
||||
if (result.ToLocal(&res)) {
|
||||
return args.GetReturnValue().Set(res);
|
||||
}
|
||||
|
||||
return args.GetReturnValue().Set(result.ToLocalChecked());
|
||||
return args.GetReturnValue().Set(status);
|
||||
}
|
||||
|
||||
void ICUErrorName(const FunctionCallbackInfo<Value>& args) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
CHECK(args[0]->IsInt32());
|
||||
UErrorCode status = static_cast<UErrorCode>(args[0].As<Int32>()->Value());
|
||||
args.GetReturnValue().Set(
|
||||
String::NewFromUtf8(env->isolate(),
|
||||
u_errorName(status)).ToLocalChecked());
|
||||
Local<Value> res;
|
||||
if (String::NewFromUtf8(env->isolate(), u_errorName(status)).ToLocal(&res)) {
|
||||
args.GetReturnValue().Set(res);
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
@@ -390,7 +394,10 @@ void ConverterObject::Create(const FunctionCallbackInfo<Value>& args) {
|
||||
|
||||
CHECK_GE(args.Length(), 2);
|
||||
Utf8Value label(env->isolate(), args[0]);
|
||||
int flags = args[1]->Uint32Value(env->context()).ToChecked();
|
||||
uint32_t flags;
|
||||
if (!args[1]->Uint32Value(env->context()).To(&flags)) {
|
||||
return;
|
||||
}
|
||||
bool fatal =
|
||||
(flags & CONVERTER_FLAGS_FATAL) == CONVERTER_FLAGS_FATAL;
|
||||
|
||||
@@ -430,7 +437,10 @@ void ConverterObject::Decode(const FunctionCallbackInfo<Value>& args) {
|
||||
}
|
||||
|
||||
ArrayBufferViewContents<char> input(args[1]);
|
||||
int flags = args[2]->Uint32Value(env->context()).ToChecked();
|
||||
uint32_t flags;
|
||||
if (!args[2]->Uint32Value(env->context()).To(&flags)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK(args[3]->IsString());
|
||||
Local<String> from_encoding = args[3].As<String>();
|
||||
|
||||
@@ -1150,16 +1150,16 @@ void MessagePort::ReceiveMessage(const FunctionCallbackInfo<Value>& args) {
|
||||
MessagePort* port = Unwrap<MessagePort>(args[0].As<Object>());
|
||||
if (port == nullptr) {
|
||||
// Return 'no messages' for a closed port.
|
||||
args.GetReturnValue().Set(
|
||||
Environment::GetCurrent(args)->no_message_symbol());
|
||||
args.GetReturnValue().Set(env->no_message_symbol());
|
||||
return;
|
||||
}
|
||||
|
||||
MaybeLocal<Value> payload =
|
||||
port->ReceiveMessage(port->object()->GetCreationContextChecked(),
|
||||
MessageProcessingMode::kForceReadMessages);
|
||||
if (!payload.IsEmpty())
|
||||
args.GetReturnValue().Set(payload.ToLocalChecked());
|
||||
Local<Value> payload;
|
||||
if (port->ReceiveMessage(port->object()->GetCreationContextChecked(),
|
||||
MessageProcessingMode::kForceReadMessages)
|
||||
.ToLocal(&payload)) {
|
||||
args.GetReturnValue().Set(payload);
|
||||
}
|
||||
}
|
||||
|
||||
void MessagePort::MoveToContext(const FunctionCallbackInfo<Value>& args) {
|
||||
|
||||
@@ -398,9 +398,10 @@ void BindingData::GetNearestParentPackageJSONType(
|
||||
return;
|
||||
}
|
||||
|
||||
Local<Value> value =
|
||||
ToV8Value(realm->context(), package_json->type).ToLocalChecked();
|
||||
args.GetReturnValue().Set(value);
|
||||
Local<Value> value;
|
||||
if (ToV8Value(realm->context(), package_json->type).ToLocal(&value)) {
|
||||
args.GetReturnValue().Set(value);
|
||||
}
|
||||
}
|
||||
|
||||
void BindingData::GetPackageScopeConfig(
|
||||
@@ -462,12 +463,11 @@ void BindingData::GetPackageScopeConfig(
|
||||
auto package_json_url_as_path =
|
||||
url::FileURLToPath(realm->env(), *package_json_url);
|
||||
CHECK(package_json_url_as_path);
|
||||
return args.GetReturnValue().Set(
|
||||
String::NewFromUtf8(realm->isolate(),
|
||||
package_json_url_as_path->c_str(),
|
||||
NewStringType::kNormal,
|
||||
package_json_url_as_path->size())
|
||||
.ToLocalChecked());
|
||||
Local<Value> ret;
|
||||
if (ToV8Value(realm->context(), *package_json_url_as_path, realm->isolate())
|
||||
.ToLocal(&ret)) {
|
||||
args.GetReturnValue().Set(ret);
|
||||
}
|
||||
}
|
||||
|
||||
void FlushCompileCache(const FunctionCallbackInfo<Value>& args) {
|
||||
@@ -499,11 +499,13 @@ void EnableCompileCache(const FunctionCallbackInfo<Value>& args) {
|
||||
}
|
||||
Utf8Value value(isolate, args[0]);
|
||||
CompileCacheEnableResult result = env->EnableCompileCache(*value);
|
||||
Local<Value> values[] = {
|
||||
v8::Integer::New(isolate, static_cast<uint8_t>(result.status)),
|
||||
ToV8Value(context, result.message).ToLocalChecked(),
|
||||
ToV8Value(context, result.cache_directory).ToLocalChecked()};
|
||||
args.GetReturnValue().Set(Array::New(isolate, &values[0], arraysize(values)));
|
||||
Local<Value> values[3];
|
||||
values[0] = v8::Integer::New(isolate, static_cast<uint8_t>(result.status));
|
||||
if (ToV8Value(context, result.message).ToLocal(&values[1]) &&
|
||||
ToV8Value(context, result.cache_directory).ToLocal(&values[2])) {
|
||||
args.GetReturnValue().Set(
|
||||
Array::New(isolate, &values[0], arraysize(values)));
|
||||
}
|
||||
}
|
||||
|
||||
void GetCompileCacheDir(const FunctionCallbackInfo<Value>& args) {
|
||||
@@ -514,9 +516,12 @@ void GetCompileCacheDir(const FunctionCallbackInfo<Value>& args) {
|
||||
args.GetReturnValue().Set(v8::String::Empty(isolate));
|
||||
return;
|
||||
}
|
||||
args.GetReturnValue().Set(
|
||||
ToV8Value(context, env->compile_cache_handler()->cache_dir())
|
||||
.ToLocalChecked());
|
||||
|
||||
Local<Value> ret;
|
||||
if (ToV8Value(context, env->compile_cache_handler()->cache_dir())
|
||||
.ToLocal(&ret)) {
|
||||
args.GetReturnValue().Set(ret);
|
||||
}
|
||||
}
|
||||
|
||||
void GetCompileCacheEntry(const FunctionCallbackInfo<Value>& args) {
|
||||
|
||||
@@ -1364,9 +1364,11 @@ void GetCLIOptionsValues(const FunctionCallbackInfo<Value>& args) {
|
||||
std::string negated_name =
|
||||
"--no" + item.first.substr(1, item.first.size());
|
||||
Local<Value> negated_value = Boolean::New(isolate, !original_value);
|
||||
Local<Name> negated_name_v8 =
|
||||
ToV8Value(context, negated_name).ToLocalChecked().As<Name>();
|
||||
option_names.push_back(negated_name_v8);
|
||||
Local<Value> negated_name_v8;
|
||||
if (!ToV8Value(context, negated_name).ToLocal(&negated_name_v8)) {
|
||||
return;
|
||||
}
|
||||
option_names.push_back(negated_name_v8.As<Name>());
|
||||
option_values.push_back(negated_value);
|
||||
break;
|
||||
}
|
||||
@@ -1414,9 +1416,11 @@ void GetCLIOptionsValues(const FunctionCallbackInfo<Value>& args) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
CHECK(!value.IsEmpty());
|
||||
Local<Name> name =
|
||||
ToV8Value(context, item.first).ToLocalChecked().As<Name>();
|
||||
option_names.push_back(name);
|
||||
Local<Value> name;
|
||||
if (!ToV8Value(context, item.first).ToLocal(&name)) {
|
||||
return;
|
||||
}
|
||||
option_names.push_back(name.As<Name>());
|
||||
option_values.push_back(value);
|
||||
}
|
||||
|
||||
@@ -1455,10 +1459,10 @@ void GetCLIOptionsInfo(const FunctionCallbackInfo<Value>& args) {
|
||||
const auto& option_info = item.second;
|
||||
auto field = option_info.field;
|
||||
|
||||
Local<Name> name =
|
||||
ToV8Value(context, item.first).ToLocalChecked().As<Name>();
|
||||
Local<Value> name;
|
||||
Local<Value> help_text;
|
||||
if (!ToV8Value(context, option_info.help_text).ToLocal(&help_text)) {
|
||||
if (!ToV8Value(context, item.first).ToLocal(&name) ||
|
||||
!ToV8Value(context, option_info.help_text).ToLocal(&help_text)) {
|
||||
return;
|
||||
}
|
||||
constexpr size_t kInfoSize = 4;
|
||||
|
||||
@@ -136,14 +136,15 @@ static void Cwd(const FunctionCallbackInfo<Value>& args) {
|
||||
char buf[PATH_MAX_BYTES];
|
||||
size_t cwd_len = sizeof(buf);
|
||||
int err = uv_cwd(buf, &cwd_len);
|
||||
if (err)
|
||||
if (err) {
|
||||
return env->ThrowUVException(err, "uv_cwd");
|
||||
}
|
||||
|
||||
Local<String> cwd = String::NewFromUtf8(env->isolate(),
|
||||
buf,
|
||||
NewStringType::kNormal,
|
||||
cwd_len).ToLocalChecked();
|
||||
args.GetReturnValue().Set(cwd);
|
||||
Local<String> cwd;
|
||||
if (String::NewFromUtf8(env->isolate(), buf, NewStringType::kNormal, cwd_len)
|
||||
.ToLocal(&cwd)) {
|
||||
args.GetReturnValue().Set(cwd);
|
||||
}
|
||||
}
|
||||
|
||||
static void Kill(const FunctionCallbackInfo<Value>& args) {
|
||||
|
||||
@@ -22,21 +22,20 @@ using v8::Isolate;
|
||||
using v8::Local;
|
||||
using v8::MaybeLocal;
|
||||
using v8::Name;
|
||||
using v8::NewStringType;
|
||||
using v8::None;
|
||||
using v8::Object;
|
||||
using v8::PropertyCallbackInfo;
|
||||
using v8::SideEffectType;
|
||||
using v8::String;
|
||||
using v8::Value;
|
||||
|
||||
static void ProcessTitleGetter(Local<Name> property,
|
||||
const PropertyCallbackInfo<Value>& info) {
|
||||
std::string title = GetProcessTitle("node");
|
||||
info.GetReturnValue().Set(
|
||||
String::NewFromUtf8(info.GetIsolate(), title.data(),
|
||||
NewStringType::kNormal, title.size())
|
||||
.ToLocalChecked());
|
||||
Local<Value> ret;
|
||||
auto isolate = info.GetIsolate();
|
||||
if (ToV8Value(isolate->GetCurrentContext(), title, isolate).ToLocal(&ret)) {
|
||||
info.GetReturnValue().Set(ret);
|
||||
}
|
||||
}
|
||||
|
||||
static void ProcessTitleSetter(Local<Name> property,
|
||||
@@ -196,28 +195,34 @@ void PatchProcessObject(const FunctionCallbackInfo<Value>& args) {
|
||||
.FromJust());
|
||||
|
||||
// process.argv
|
||||
process->Set(context,
|
||||
FIXED_ONE_BYTE_STRING(isolate, "argv"),
|
||||
ToV8Value(context, env->argv()).ToLocalChecked()).Check();
|
||||
Local<Value> val;
|
||||
if (!ToV8Value(context, env->argv()).ToLocal(&val) ||
|
||||
!process->Set(context, FIXED_ONE_BYTE_STRING(isolate, "argv"), val)
|
||||
.IsJust()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// process.execArgv
|
||||
process->Set(context,
|
||||
FIXED_ONE_BYTE_STRING(isolate, "execArgv"),
|
||||
ToV8Value(context, env->exec_argv())
|
||||
.ToLocalChecked()).Check();
|
||||
if (!ToV8Value(context, env->exec_argv()).ToLocal(&val) ||
|
||||
!process->Set(context, FIXED_ONE_BYTE_STRING(isolate, "execArgv"), val)
|
||||
.IsJust()) {
|
||||
return;
|
||||
}
|
||||
|
||||
READONLY_PROPERTY(process, "pid",
|
||||
Integer::New(isolate, uv_os_getpid()));
|
||||
|
||||
CHECK(process
|
||||
->SetNativeDataProperty(context,
|
||||
FIXED_ONE_BYTE_STRING(isolate, "ppid"),
|
||||
GetParentProcessId,
|
||||
nullptr,
|
||||
Local<Value>(),
|
||||
None,
|
||||
SideEffectType::kHasNoSideEffect)
|
||||
.FromJust());
|
||||
if (!process
|
||||
->SetNativeDataProperty(context,
|
||||
FIXED_ONE_BYTE_STRING(isolate, "ppid"),
|
||||
GetParentProcessId,
|
||||
nullptr,
|
||||
Local<Value>(),
|
||||
None,
|
||||
SideEffectType::kHasNoSideEffect)
|
||||
.IsJust()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// --security-revert flags
|
||||
#define V(code, _, __) \
|
||||
@@ -230,27 +235,25 @@ void PatchProcessObject(const FunctionCallbackInfo<Value>& args) {
|
||||
#undef V
|
||||
|
||||
// process.execPath
|
||||
process
|
||||
->Set(context,
|
||||
FIXED_ONE_BYTE_STRING(isolate, "execPath"),
|
||||
String::NewFromUtf8(isolate,
|
||||
env->exec_path().c_str(),
|
||||
NewStringType::kInternalized,
|
||||
env->exec_path().size())
|
||||
.ToLocalChecked())
|
||||
.Check();
|
||||
if (!ToV8Value(context, env->exec_path(), isolate).ToLocal(&val) ||
|
||||
!process->Set(context, FIXED_ONE_BYTE_STRING(isolate, "execPath"), val)
|
||||
.IsJust()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// process.debugPort
|
||||
CHECK(process
|
||||
->SetNativeDataProperty(
|
||||
context,
|
||||
FIXED_ONE_BYTE_STRING(isolate, "debugPort"),
|
||||
DebugPortGetter,
|
||||
env->owns_process_state() ? DebugPortSetter : nullptr,
|
||||
Local<Value>(),
|
||||
None,
|
||||
SideEffectType::kHasNoSideEffect)
|
||||
.FromJust());
|
||||
if (!process
|
||||
->SetNativeDataProperty(
|
||||
context,
|
||||
FIXED_ONE_BYTE_STRING(isolate, "debugPort"),
|
||||
DebugPortGetter,
|
||||
env->owns_process_state() ? DebugPortSetter : nullptr,
|
||||
Local<Value>(),
|
||||
None,
|
||||
SideEffectType::kHasNoSideEffect)
|
||||
.IsJust()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// process.versions
|
||||
Local<Object> versions = Object::New(isolate);
|
||||
|
||||
@@ -439,10 +439,14 @@ static Maybe<std::string> ErrorToString(Isolate* isolate,
|
||||
} else if (!error->IsObject()) {
|
||||
maybe_str = error->ToString(context);
|
||||
} else if (error->IsObject()) {
|
||||
MaybeLocal<Value> stack = error.As<Object>()->Get(
|
||||
context, FIXED_ONE_BYTE_STRING(isolate, "stack"));
|
||||
if (!stack.IsEmpty() && stack.ToLocalChecked()->IsString()) {
|
||||
maybe_str = stack.ToLocalChecked().As<String>();
|
||||
Local<Value> stack;
|
||||
if (!error.As<Object>()
|
||||
->Get(context, FIXED_ONE_BYTE_STRING(isolate, "stack"))
|
||||
.ToLocal(&stack)) {
|
||||
return Nothing<std::string>();
|
||||
}
|
||||
if (stack->IsString()) {
|
||||
maybe_str = stack.As<String>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,10 +44,12 @@ void WriteReport(const FunctionCallbackInfo<Value>& info) {
|
||||
else
|
||||
error = Local<Value>();
|
||||
|
||||
filename = TriggerNodeReport(env, *message, *trigger, filename, error);
|
||||
// Return value is the report filename
|
||||
info.GetReturnValue().Set(
|
||||
String::NewFromUtf8(isolate, filename.c_str()).ToLocalChecked());
|
||||
filename = TriggerNodeReport(env, *message, *trigger, filename, error);
|
||||
Local<Value> ret;
|
||||
if (ToV8Value(env->context(), filename, env->isolate()).ToLocal(&ret)) {
|
||||
info.GetReturnValue().Set(ret);
|
||||
}
|
||||
}
|
||||
|
||||
// External JavaScript API for returning a report
|
||||
@@ -67,8 +69,10 @@ void GetReport(const FunctionCallbackInfo<Value>& info) {
|
||||
GetNodeReport(env, "JavaScript API", __func__, error, out);
|
||||
|
||||
// Return value is the contents of a report as a string.
|
||||
info.GetReturnValue().Set(
|
||||
String::NewFromUtf8(isolate, out.str().c_str()).ToLocalChecked());
|
||||
Local<Value> ret;
|
||||
if (ToV8Value(env->context(), out.str(), env->isolate()).ToLocal(&ret)) {
|
||||
info.GetReturnValue().Set(ret);
|
||||
}
|
||||
}
|
||||
|
||||
static void GetCompact(const FunctionCallbackInfo<Value>& info) {
|
||||
@@ -110,8 +114,10 @@ static void GetDirectory(const FunctionCallbackInfo<Value>& info) {
|
||||
Mutex::ScopedLock lock(per_process::cli_options_mutex);
|
||||
Environment* env = Environment::GetCurrent(info);
|
||||
std::string directory = per_process::cli_options->report_directory;
|
||||
auto result = String::NewFromUtf8(env->isolate(), directory.c_str());
|
||||
info.GetReturnValue().Set(result.ToLocalChecked());
|
||||
Local<Value> ret;
|
||||
if (ToV8Value(env->context(), directory, env->isolate()).ToLocal(&ret)) {
|
||||
info.GetReturnValue().Set(ret);
|
||||
}
|
||||
}
|
||||
|
||||
static void SetDirectory(const FunctionCallbackInfo<Value>& info) {
|
||||
@@ -126,8 +132,10 @@ static void GetFilename(const FunctionCallbackInfo<Value>& info) {
|
||||
Mutex::ScopedLock lock(per_process::cli_options_mutex);
|
||||
Environment* env = Environment::GetCurrent(info);
|
||||
std::string filename = per_process::cli_options->report_filename;
|
||||
auto result = String::NewFromUtf8(env->isolate(), filename.c_str());
|
||||
info.GetReturnValue().Set(result.ToLocalChecked());
|
||||
Local<Value> ret;
|
||||
if (ToV8Value(env->context(), filename, env->isolate()).ToLocal(&ret)) {
|
||||
info.GetReturnValue().Set(ret);
|
||||
}
|
||||
}
|
||||
|
||||
static void SetFilename(const FunctionCallbackInfo<Value>& info) {
|
||||
@@ -141,8 +149,10 @@ static void SetFilename(const FunctionCallbackInfo<Value>& info) {
|
||||
static void GetSignal(const FunctionCallbackInfo<Value>& info) {
|
||||
Environment* env = Environment::GetCurrent(info);
|
||||
std::string signal = env->isolate_data()->options()->report_signal;
|
||||
auto result = String::NewFromUtf8(env->isolate(), signal.c_str());
|
||||
info.GetReturnValue().Set(result.ToLocalChecked());
|
||||
Local<Value> ret;
|
||||
if (ToV8Value(env->context(), signal, env->isolate()).ToLocal(&ret)) {
|
||||
info.GetReturnValue().Set(ret);
|
||||
}
|
||||
}
|
||||
|
||||
static void SetSignal(const FunctionCallbackInfo<Value>& info) {
|
||||
|
||||
@@ -103,67 +103,69 @@ SerializerContext::SerializerContext(Environment* env, Local<Object> wrap)
|
||||
|
||||
void SerializerContext::ThrowDataCloneError(Local<String> message) {
|
||||
Local<Value> args[1] = { message };
|
||||
Local<Value> get_data_clone_error =
|
||||
object()->Get(env()->context(),
|
||||
env()->get_data_clone_error_string())
|
||||
.ToLocalChecked();
|
||||
Local<Value> get_data_clone_error;
|
||||
if (!object()
|
||||
->Get(env()->context(), env()->get_data_clone_error_string())
|
||||
.ToLocal(&get_data_clone_error)) {
|
||||
// A superseding error will have been thrown by v8.
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK(get_data_clone_error->IsFunction());
|
||||
MaybeLocal<Value> error =
|
||||
get_data_clone_error.As<Function>()->Call(env()->context(),
|
||||
object(),
|
||||
arraysize(args),
|
||||
args);
|
||||
|
||||
if (error.IsEmpty()) return;
|
||||
|
||||
env()->isolate()->ThrowException(error.ToLocalChecked());
|
||||
Local<Value> error;
|
||||
if (get_data_clone_error.As<Function>()
|
||||
->Call(env()->context(), object(), arraysize(args), args)
|
||||
.ToLocal(&error)) {
|
||||
env()->isolate()->ThrowException(error);
|
||||
}
|
||||
}
|
||||
|
||||
Maybe<uint32_t> SerializerContext::GetSharedArrayBufferId(
|
||||
Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer) {
|
||||
Local<Value> args[1] = { shared_array_buffer };
|
||||
Local<Value> get_shared_array_buffer_id =
|
||||
object()->Get(env()->context(),
|
||||
env()->get_shared_array_buffer_id_string())
|
||||
.ToLocalChecked();
|
||||
Local<Value> get_shared_array_buffer_id;
|
||||
if (!object()
|
||||
->Get(env()->context(), env()->get_shared_array_buffer_id_string())
|
||||
.ToLocal(&get_shared_array_buffer_id)) {
|
||||
return Nothing<uint32_t>();
|
||||
}
|
||||
|
||||
if (!get_shared_array_buffer_id->IsFunction()) {
|
||||
return ValueSerializer::Delegate::GetSharedArrayBufferId(
|
||||
isolate, shared_array_buffer);
|
||||
}
|
||||
|
||||
MaybeLocal<Value> id =
|
||||
get_shared_array_buffer_id.As<Function>()->Call(env()->context(),
|
||||
object(),
|
||||
arraysize(args),
|
||||
args);
|
||||
Local<Value> id;
|
||||
if (!get_shared_array_buffer_id.As<Function>()
|
||||
->Call(env()->context(), object(), arraysize(args), args)
|
||||
.ToLocal(&id)) {
|
||||
return Nothing<uint32_t>();
|
||||
}
|
||||
|
||||
if (id.IsEmpty()) return Nothing<uint32_t>();
|
||||
|
||||
return id.ToLocalChecked()->Uint32Value(env()->context());
|
||||
return id->Uint32Value(env()->context());
|
||||
}
|
||||
|
||||
Maybe<bool> SerializerContext::WriteHostObject(Isolate* isolate,
|
||||
Local<Object> input) {
|
||||
MaybeLocal<Value> ret;
|
||||
Local<Value> args[1] = { input };
|
||||
|
||||
Local<Value> write_host_object =
|
||||
object()->Get(env()->context(),
|
||||
env()->write_host_object_string()).ToLocalChecked();
|
||||
Local<Value> write_host_object;
|
||||
if (!object()
|
||||
->Get(env()->context(), env()->write_host_object_string())
|
||||
.ToLocal(&write_host_object)) {
|
||||
return Nothing<bool>();
|
||||
}
|
||||
|
||||
if (!write_host_object->IsFunction()) {
|
||||
return ValueSerializer::Delegate::WriteHostObject(isolate, input);
|
||||
}
|
||||
|
||||
ret = write_host_object.As<Function>()->Call(env()->context(),
|
||||
object(),
|
||||
arraysize(args),
|
||||
args);
|
||||
|
||||
if (ret.IsEmpty())
|
||||
Local<Value> ret;
|
||||
if (!write_host_object.As<Function>()
|
||||
->Call(env()->context(), object(), arraysize(args), args)
|
||||
.ToLocal(&ret)) {
|
||||
return Nothing<bool>();
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
}
|
||||
@@ -209,12 +211,10 @@ void SerializerContext::ReleaseBuffer(const FunctionCallbackInfo<Value>& args) {
|
||||
// Note: Both ValueSerializer and this Buffer::New() variant use malloc()
|
||||
// as the underlying allocator.
|
||||
std::pair<uint8_t*, size_t> ret = ctx->serializer_.Release();
|
||||
auto buf = Buffer::New(ctx->env(),
|
||||
reinterpret_cast<char*>(ret.first),
|
||||
ret.second);
|
||||
|
||||
if (!buf.IsEmpty()) {
|
||||
args.GetReturnValue().Set(buf.ToLocalChecked());
|
||||
Local<Object> buf;
|
||||
if (Buffer::New(ctx->env(), reinterpret_cast<char*>(ret.first), ret.second)
|
||||
.ToLocal(&buf)) {
|
||||
args.GetReturnValue().Set(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,31 +295,31 @@ DeserializerContext::DeserializerContext(Environment* env,
|
||||
}
|
||||
|
||||
MaybeLocal<Object> DeserializerContext::ReadHostObject(Isolate* isolate) {
|
||||
Local<Value> read_host_object =
|
||||
object()->Get(env()->context(),
|
||||
env()->read_host_object_string()).ToLocalChecked();
|
||||
Local<Value> read_host_object;
|
||||
if (!object()
|
||||
->Get(env()->context(), env()->read_host_object_string())
|
||||
.ToLocal(&read_host_object)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!read_host_object->IsFunction()) {
|
||||
return ValueDeserializer::Delegate::ReadHostObject(isolate);
|
||||
}
|
||||
|
||||
Isolate::AllowJavascriptExecutionScope allow_js(isolate);
|
||||
MaybeLocal<Value> ret =
|
||||
read_host_object.As<Function>()->Call(env()->context(),
|
||||
object(),
|
||||
0,
|
||||
nullptr);
|
||||
|
||||
if (ret.IsEmpty())
|
||||
return MaybeLocal<Object>();
|
||||
|
||||
Local<Value> return_value = ret.ToLocalChecked();
|
||||
if (!return_value->IsObject()) {
|
||||
env()->ThrowTypeError("readHostObject must return an object");
|
||||
return MaybeLocal<Object>();
|
||||
Local<Value> ret;
|
||||
if (!read_host_object.As<Function>()
|
||||
->Call(env()->context(), object(), 0, nullptr)
|
||||
.ToLocal(&ret)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return return_value.As<Object>();
|
||||
if (!ret->IsObject()) {
|
||||
env()->ThrowTypeError("readHostObject must return an object");
|
||||
return {};
|
||||
}
|
||||
|
||||
return ret.As<Object>();
|
||||
}
|
||||
|
||||
void DeserializerContext::New(const FunctionCallbackInfo<Value>& args) {
|
||||
@@ -350,9 +350,10 @@ void DeserializerContext::ReadValue(const FunctionCallbackInfo<Value>& args) {
|
||||
DeserializerContext* ctx;
|
||||
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.This());
|
||||
|
||||
MaybeLocal<Value> ret = ctx->deserializer_.ReadValue(ctx->env()->context());
|
||||
|
||||
if (!ret.IsEmpty()) args.GetReturnValue().Set(ret.ToLocalChecked());
|
||||
Local<Value> ret;
|
||||
if (ctx->deserializer_.ReadValue(ctx->env()->context()).ToLocal(&ret)) {
|
||||
args.GetReturnValue().Set(ret);
|
||||
}
|
||||
}
|
||||
|
||||
void DeserializerContext::TransferArrayBuffer(
|
||||
|
||||
@@ -24,7 +24,6 @@ using v8::FunctionCallbackInfo;
|
||||
using v8::FunctionTemplate;
|
||||
using v8::Isolate;
|
||||
using v8::Local;
|
||||
using v8::NewStringType;
|
||||
using v8::Object;
|
||||
using v8::String;
|
||||
using v8::Uint8Array;
|
||||
@@ -107,12 +106,10 @@ void GetEnabledCategories(const FunctionCallbackInfo<Value>& args) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
std::string categories =
|
||||
GetTracingAgentWriter()->agent()->GetEnabledCategories();
|
||||
if (!categories.empty()) {
|
||||
args.GetReturnValue().Set(
|
||||
String::NewFromUtf8(env->isolate(),
|
||||
categories.c_str(),
|
||||
NewStringType::kNormal,
|
||||
categories.size()).ToLocalChecked());
|
||||
Local<Value> ret;
|
||||
if (!categories.empty() &&
|
||||
ToV8Value(env->context(), categories, env->isolate()).ToLocal(&ret)) {
|
||||
args.GetReturnValue().Set(ret);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -409,11 +409,10 @@ void GCProfiler::Stop(const FunctionCallbackInfo<v8::Value>& args) {
|
||||
profiler->writer()->json_end();
|
||||
profiler->state = GCProfiler::GCProfilerState::kStopped;
|
||||
auto string = profiler->out_stream()->str();
|
||||
args.GetReturnValue().Set(String::NewFromUtf8(env->isolate(),
|
||||
string.data(),
|
||||
v8::NewStringType::kNormal,
|
||||
string.size())
|
||||
.ToLocalChecked());
|
||||
Local<Value> ret;
|
||||
if (ToV8Value(env->context(), string, env->isolate()).ToLocal(&ret)) {
|
||||
args.GetReturnValue().Set(ret);
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize(Local<Object> target,
|
||||
|
||||
Reference in New Issue
Block a user