From f30f11bd5db889ff66d890427af7e8a2245a4495 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 20 Oct 2018 13:50:10 +0200 Subject: [PATCH] test: verify `performance.timerify()` works w/ non-Node Contexts PR-URL: https://github.com/nodejs/node/pull/23784 Reviewed-By: Refael Ackermann Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/node_perf.cc | 2 +- test/addons/non-node-context/binding.cc | 55 +++++++++++++++++++ test/addons/non-node-context/binding.gyp | 8 +++ .../test-perf-hooks-timerify.js | 17 ++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 test/addons/non-node-context/binding.cc create mode 100644 test/addons/non-node-context/binding.gyp create mode 100644 test/addons/non-node-context/test-perf-hooks-timerify.js diff --git a/src/node_perf.cc b/src/node_perf.cc index 204996384af3a3..aed97d2b3b263a 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -310,7 +310,7 @@ void TimerFunctionCall(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); Environment* env = Environment::GetCurrent(isolate); - CHECK_NOT_NULL(env); // TODO(addaleax): Verify that this is correct. + CHECK_NOT_NULL(env); Local context = env->context(); Local fn = args.Data().As(); size_t count = args.Length(); diff --git a/test/addons/non-node-context/binding.cc b/test/addons/non-node-context/binding.cc new file mode 100644 index 00000000000000..324f5c5a1ef16f --- /dev/null +++ b/test/addons/non-node-context/binding.cc @@ -0,0 +1,55 @@ +#include +#include + +namespace { + +using v8::Context; +using v8::Function; +using v8::FunctionTemplate; +using v8::Isolate; +using v8::Local; +using v8::MaybeLocal; +using v8::NewStringType; +using v8::Object; +using v8::Script; +using v8::String; +using v8::Value; + +inline void RunInNewContext( + const v8::FunctionCallbackInfo& args) { + Isolate* isolate = args.GetIsolate(); + Local context = Context::New(isolate); + Context::Scope context_scope(context); + + context->Global()->Set( + context, + String::NewFromUtf8(isolate, "data", NewStringType::kNormal) + .ToLocalChecked(), + args[1]).FromJust(); + + assert(args[0]->IsString()); // source code + Local