Commit dd704218 authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

[async] Improve error handling for async hooks

Replace CHECK with throwing exception when no or invalid arguments
are passed to async_hooks.createHook.

Bug: chromium:860481
Change-Id: Ie5a915ee66f2a0ff79c4df5aef94ff883866ecda
Reviewed-on: https://chromium-review.googlesource.com/1127054Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54264}
parent f45045cc
......@@ -72,9 +72,15 @@ Local<Object> AsyncHooks::CreateHook(
Local<Context> currentContext = isolate->GetCurrentContext();
AsyncHooksWrap* wrap = new AsyncHooksWrap(isolate);
if (args.Length() != 1 || !args[0]->IsObject()) {
isolate->ThrowException(
String::NewFromUtf8(isolate, "Invalid arguments passed to createHook",
NewStringType::kNormal)
.ToLocalChecked());
return Local<Object>();
}
CHECK(args[0]->IsObject());
AsyncHooksWrap* wrap = new AsyncHooksWrap(isolate);
Local<Object> fn_obj = args[0].As<Object>();
......
......@@ -27,10 +27,18 @@
// Flags: --expose-async-hooks
// Check for correct API methods
// Check for invalid arguments handling
(function() {
assertTrue(async_hooks.hasOwnProperty('createHook'),
'Async hooks missing createHook method');
assertThrows(() => async_hooks.createHook());
assertThrows(() => async_hooks.createHook(123));
assertThrows(() => async_hooks.createHook('str'));
})();
// Check for correct API methods
(function() {
assertTrue(async_hooks.hasOwnProperty('executionAsyncId'),
'Async hooks missing executionAsyncId method');
assertTrue(async_hooks.hasOwnProperty('triggerAsyncId'),
......
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