Commit 9555464f authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[d8] Fix worker creation near stack limit

If we are near the stack limit, calling the proxy method might not work
any more. Instead of crashing because of an empty MaybeLocal, handle
this gracefully.

Drive-by: Minor refactoring in TryGetValue.

R=tebbi@chromium.org

Bug: chromium:1110001
Change-Id: I07e7773768166b3dbea2e6b75a3ab8b24bfeee53
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2332156Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69161}
parent 13141c8a
......@@ -339,10 +339,9 @@ static MaybeLocal<Value> TryGetValue(v8::Isolate* isolate,
Local<Context> context,
Local<v8::Object> object,
const char* property) {
Local<String> v8_str =
String::NewFromUtf8(isolate, property).FromMaybe(Local<String>());
if (v8_str.IsEmpty()) return Local<Value>();
return object->Get(context, v8_str);
MaybeLocal<String> v8_str = String::NewFromUtf8(isolate, property);
if (v8_str.IsEmpty()) return {};
return object->Get(context, v8_str.ToLocalChecked());
}
static Local<Value> GetValue(v8::Isolate* isolate, Local<Context> context,
......@@ -1688,8 +1687,10 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() > 1 && args[1]->IsObject()) {
Local<Object> object = args[1].As<Object>();
Local<Context> context = isolate->GetCurrentContext();
Local<Value> value = GetValue(args.GetIsolate(), context, object, "type");
if (value->IsString()) {
Local<Value> value;
if (TryGetValue(args.GetIsolate(), context, object, "type")
.ToLocal(&value) &&
value->IsString()) {
Local<String> worker_type = value->ToString(context).ToLocalChecked();
String::Utf8Value str(isolate, worker_type);
if (strcmp("string", *str) == 0) {
......
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function foo() {
try {
foo();
} catch {
print('Stack overflow');
Worker('string', new Proxy([], {}));
}
}
try {
foo();
} catch {
// expecting stack overflow, but we should not crash.
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment