[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/+/2332156
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69161}
This commit is contained in:
Clemens Backes 2020-07-31 08:30:27 +02:00 committed by Commit Bot
parent 13141c8a65
commit 9555464fb2
2 changed files with 24 additions and 6 deletions

View File

@ -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) {

View File

@ -0,0 +1,17 @@
// 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.
}