diff --git a/src/d8/async-hooks-wrapper.cc b/src/d8/async-hooks-wrapper.cc index 897736f19f..dccc5e515b 100644 --- a/src/d8/async-hooks-wrapper.cc +++ b/src/d8/async-hooks-wrapper.cc @@ -134,12 +134,12 @@ Local AsyncHooks::CreateHook( Local fn_obj = args[0].As(); -#define SET_HOOK_FN(name) \ - Local name##_v = \ - fn_obj->Get(currentContext, String::NewFromUtf8Literal(isolate, #name)) \ - .ToLocalChecked(); \ - if (name##_v->IsFunction()) { \ - wrap->set_##name##_function(name##_v.As()); \ +#define SET_HOOK_FN(name) \ + MaybeLocal name##_maybe_func = \ + fn_obj->Get(currentContext, String::NewFromUtf8Literal(isolate, #name)); \ + Local name##_func; \ + if (name##_maybe_func.ToLocal(&name##_func) && name##_func->IsFunction()) { \ + wrap->set_##name##_function(name##_func.As()); \ } SET_HOOK_FN(init); diff --git a/test/mjsunit/async-hooks/regress-crbug-1337629.js b/test/mjsunit/async-hooks/regress-crbug-1337629.js new file mode 100644 index 0000000000..1570d3fd0a --- /dev/null +++ b/test/mjsunit/async-hooks/regress-crbug-1337629.js @@ -0,0 +1,11 @@ +// Copyright 2022 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. + +const failing_proxy = new Proxy({}, new Proxy({}, { + get() { + throw "No trap should fire"; + } +})); + +assertThrows(() => async_hooks.createHook(failing_proxy));