| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f9d0166 commit a485612
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -121,18 +121,35 @@ static void SetupHooks(const FunctionCallbackInfo<Value>& args) { | |||
| 121 | 121 | ||
| 122 | 122 | if (env->async_hooks()->callbacks_enabled()) | |
| 123 | 123 | return env->ThrowError("hooks should not be set while also enabled"); | |
| 124 | - | ||
| 125 | - if (!args[0]->IsFunction()) | ||
| 124 | + if (!args[0]->IsObject()) | ||
| 125 | + return env->ThrowTypeError("first argument must be an object"); | ||
| 126 | + | ||
| 127 | + Local<Object> fn_obj = args[0].As<Object>(); | ||
| 128 | + | ||
| 129 | + Local<Value> init_v = fn_obj->Get( | ||
| 130 | + env->context(), | ||
| 131 | + FIXED_ONE_BYTE_STRING(env->isolate(), "init")).ToLocalChecked(); | ||
| 132 | + Local<Value> pre_v = fn_obj->Get( | ||
| 133 | + env->context(), | ||
| 134 | + FIXED_ONE_BYTE_STRING(env->isolate(), "pre")).ToLocalChecked(); | ||
| 135 | + Local<Value> post_v = fn_obj->Get( | ||
| 136 | + env->context(), | ||
| 137 | + FIXED_ONE_BYTE_STRING(env->isolate(), "post")).ToLocalChecked(); | ||
| 138 | + Local<Value> destroy_v = fn_obj->Get( | ||
| 139 | + env->context(), | ||
| 140 | + FIXED_ONE_BYTE_STRING(env->isolate(), "destroy")).ToLocalChecked(); | ||
| 141 | + | ||
| 142 | + if (!init_v->IsFunction()) | ||
| 126 | 143 | return env->ThrowTypeError("init callback must be a function"); | |
| 127 | 144 | ||
| 128 | - env->set_async_hooks_init_function(args[0].As<Function>()); | ||
| 145 | + env->set_async_hooks_init_function(init_v.As<Function>()); | ||
| 129 | 146 | ||
| 130 | - if (args[1]->IsFunction()) | ||
| 131 | - env->set_async_hooks_pre_function(args[1].As<Function>()); | ||
| 132 | - if (args[2]->IsFunction()) | ||
| 133 | - env->set_async_hooks_post_function(args[2].As<Function>()); | ||
| 134 | - if (args[3]->IsFunction()) | ||
| 135 | - env->set_async_hooks_destroy_function(args[3].As<Function>()); | ||
| 147 | + if (pre_v->IsFunction()) | ||
| 148 | + env->set_async_hooks_pre_function(pre_v.As<Function>()); | ||
| 149 | + if (post_v->IsFunction()) | ||
| 150 | + env->set_async_hooks_post_function(post_v.As<Function>()); | ||
| 151 | + if (destroy_v->IsFunction()) | ||
| 152 | + env->set_async_hooks_destroy_function(destroy_v.As<Function>()); | ||
| 136 | 153 | } | |
| 137 | 154 | ||
| 138 | 155 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ function init(id, provider) { | |||
| 36 | 36 | ||
| 37 | 37 | function noop() { } | |
| 38 | 38 | ||
| 39 | - async_wrap.setupHooks(init, noop, noop); | ||
| 39 | + async_wrap.setupHooks({ init }); | ||
| 40 | 40 | ||
| 41 | 41 | async_wrap.enable(); | |
| 42 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,7 +31,7 @@ function init(uid, type, parentUid, parentHandle) { | |||
| 31 | 31 | ||
| 32 | 32 | function noop() { } | |
| 33 | 33 | ||
| 34 | - async_wrap.setupHooks(init, noop, noop); | ||
| 34 | + async_wrap.setupHooks({ init }); | ||
| 35 | 35 | async_wrap.enable(); | |
| 36 | 36 | ||
| 37 | 37 | server = net.createServer(function(c) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,7 +31,7 @@ function init(uid, type, parentUid, parentHandle) { | |||
| 31 | 31 | ||
| 32 | 32 | function noop() { } | |
| 33 | 33 | ||
| 34 | - async_wrap.setupHooks(init, noop, noop); | ||
| 34 | + async_wrap.setupHooks({ init }); | ||
| 35 | 35 | async_wrap.enable(); | |
| 36 | 36 | ||
| 37 | 37 | server = net.createServer(function(c) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,14 +7,14 @@ const async_wrap = process.binding('async_wrap'); | |||
| 7 | 7 | ||
| 8 | 8 | assert.throws(function() { | |
| 9 | 9 | async_wrap.setupHooks(null); | |
| 10 | - }, /init callback must be a function/); | ||
| 10 | + }, /first argument must be an object/); | ||
| 11 | 11 | ||
| 12 | 12 | assert.throws(function() { | |
| 13 | 13 | async_wrap.enable(); | |
| 14 | 14 | }, /init callback is not assigned to a function/); | |
| 15 | 15 | ||
| 16 | 16 | // Should not throw | |
| 17 | - async_wrap.setupHooks(() => {}); | ||
| 17 | + async_wrap.setupHooks({ init: () => {} }); | ||
| 18 | 18 | async_wrap.enable(); | |
| 19 | 19 | ||
| 20 | 20 | assert.throws(function() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ const assert = require('assert'); | |||
| 6 | 6 | const async_wrap = process.binding('async_wrap'); | |
| 7 | 7 | ||
| 8 | 8 | const storage = new Map(); | |
| 9 | - async_wrap.setupHooks(init, pre, post, destroy); | ||
| 9 | + async_wrap.setupHooks({ init, pre, post, destroy }); | ||
| 10 | 10 | async_wrap.enable(); | |
| 11 | 11 | ||
| 12 | 12 | function init(uid) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments