From 284caaa852194f7418d24c44f2df58614437f3cc Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 19 Jul 2018 16:37:41 -0700 Subject: deps: V8: Backport of 0dd3390 from upstream Original commit message: Reland "[builtins] Add %IsTraceCategoryEnabled and %Trace builtins" This is a reland of 8d4572a Original change's description: > [builtins] Add %IsTraceCategoryEnabled and %Trace builtins > > Adds the builtin Trace and IsTraceCategoryEnabled functions > exposed via extra bindings. These are intended to use by > embedders to allow basic trace event support from JavaScript. > > ```js > isTraceCategoryEnabled('v8.some-category') > > trace('e'.charCodeAt(0), 'v8.some-category', > 'Foo', 0, { abc: 'xyz'}) > ``` > > Bug: v8:7851 > Change-Id: I7bfb9bb059efdf87d92a56a0aae326650730c250 > Reviewed-on: chromium-review.googlesource.com/1103294 > Commit-Queue: Yang Guo > Reviewed-by: Yang Guo > Reviewed-by: Fadi Meawad > Reviewed-by: Camillo Bruni > Reviewed-by: Benedikt Meurer > Cr-Commit-Position: refs/heads/master@{#54121} TBR=cbruni@chromium.org Bug: v8:7851 Change-Id: Id063754b2834b3b6a2b2654e76e8637bcd6aa5f8 Reviewed-on: chromium-review.googlesource.com/1137071 Commit-Queue: Yang Guo Reviewed-by: Yang Guo Reviewed-by: Camillo Bruni Reviewed-by: Benedikt Meurer Cr-Commit-Position: refs/heads/master@{#54532} PR-URL: https://github.com/nodejs/node/pull/21899 Reviewed-By: Ali Ijaz Sheikh --- deps/v8/test/cctest/test-trace-event.cc | 134 +++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) (limited to 'deps/v8/test') diff --git a/deps/v8/test/cctest/test-trace-event.cc b/deps/v8/test/cctest/test-trace-event.cc index 7b736b907d..47545af37f 100644 --- a/deps/v8/test/cctest/test-trace-event.cc +++ b/deps/v8/test/cctest/test-trace-event.cc @@ -75,7 +75,7 @@ class MockTracingController : public v8::TracingController { const char* name, uint64_t handle) override {} const uint8_t* GetCategoryGroupEnabled(const char* name) override { - if (strcmp(name, "v8-cat")) { + if (strncmp(name, "v8-cat", 6)) { static uint8_t no = 0; return &no; } else { @@ -282,3 +282,135 @@ TEST(TestEventWithTimestamp) { CHECK_EQ(20683, GET_TRACE_OBJECT(3)->timestamp); CHECK_EQ(32832, GET_TRACE_OBJECT(4)->timestamp); } + +TEST(BuiltinsIsTraceCategoryEnabled) { + CcTest::InitializeVM(); + MockTracingPlatform platform; + + v8::Isolate* isolate = CcTest::isolate(); + v8::HandleScope handle_scope(isolate); + LocalContext env; + + v8::Local binding = env->GetExtrasBindingObject(); + CHECK(!binding.IsEmpty()); + + auto undefined = v8::Undefined(isolate); + auto isTraceCategoryEnabled = + binding->Get(env.local(), v8_str("isTraceCategoryEnabled")) + .ToLocalChecked() + .As(); + + { + // Test with an enabled category + v8::Local argv[] = {v8_str("v8-cat")}; + auto result = isTraceCategoryEnabled->Call(env.local(), undefined, 1, argv) + .ToLocalChecked() + .As(); + + CHECK(result->BooleanValue()); + } + + { + // Test with a disabled category + v8::Local argv[] = {v8_str("cat")}; + auto result = isTraceCategoryEnabled->Call(env.local(), undefined, 1, argv) + .ToLocalChecked() + .As(); + + CHECK(!result->BooleanValue()); + } + + { + // Test with an enabled utf8 category + v8::Local argv[] = {v8_str("v8-cat\u20ac")}; + auto result = isTraceCategoryEnabled->Call(env.local(), undefined, 1, argv) + .ToLocalChecked() + .As(); + + CHECK(result->BooleanValue()); + } +} + +TEST(BuiltinsTrace) { + CcTest::InitializeVM(); + MockTracingPlatform platform; + + v8::Isolate* isolate = CcTest::isolate(); + v8::HandleScope handle_scope(isolate); + LocalContext env; + + v8::Local binding = env->GetExtrasBindingObject(); + CHECK(!binding.IsEmpty()); + + auto undefined = v8::Undefined(isolate); + auto trace = binding->Get(env.local(), v8_str("trace")) + .ToLocalChecked() + .As(); + + // Test with disabled category + { + v8::Local category = v8_str("cat"); + v8::Local name = v8_str("name"); + v8::Local argv[] = { + v8::Integer::New(isolate, 'b'), // phase + category, name, v8::Integer::New(isolate, 0), // id + undefined // data + }; + auto result = trace->Call(env.local(), undefined, 5, argv) + .ToLocalChecked() + .As(); + + CHECK(!result->BooleanValue()); + CHECK_EQ(0, GET_TRACE_OBJECTS_LIST->size()); + } + + // Test with enabled category + { + v8::Local category = v8_str("v8-cat"); + v8::Local name = v8_str("name"); + v8::Local context = isolate->GetCurrentContext(); + v8::Local data = v8::Object::New(isolate); + data->Set(context, v8_str("foo"), v8_str("bar")).FromJust(); + v8::Local argv[] = { + v8::Integer::New(isolate, 'b'), // phase + category, name, v8::Integer::New(isolate, 123), // id + data // data arg + }; + auto result = trace->Call(env.local(), undefined, 5, argv) + .ToLocalChecked() + .As(); + + CHECK(result->BooleanValue()); + CHECK_EQ(1, GET_TRACE_OBJECTS_LIST->size()); + + CHECK_EQ(123, GET_TRACE_OBJECT(0)->id); + CHECK_EQ('b', GET_TRACE_OBJECT(0)->phase); + CHECK_EQ("name", GET_TRACE_OBJECT(0)->name); + CHECK_EQ(1, GET_TRACE_OBJECT(0)->num_args); + } + + // Test with enabled utf8 category + { + v8::Local category = v8_str("v8-cat\u20ac"); + v8::Local name = v8_str("name\u20ac"); + v8::Local context = isolate->GetCurrentContext(); + v8::Local data = v8::Object::New(isolate); + data->Set(context, v8_str("foo"), v8_str("bar")).FromJust(); + v8::Local argv[] = { + v8::Integer::New(isolate, 'b'), // phase + category, name, v8::Integer::New(isolate, 123), // id + data // data arg + }; + auto result = trace->Call(env.local(), undefined, 5, argv) + .ToLocalChecked() + .As(); + + CHECK(result->BooleanValue()); + CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->size()); + + CHECK_EQ(123, GET_TRACE_OBJECT(1)->id); + CHECK_EQ('b', GET_TRACE_OBJECT(1)->phase); + CHECK_EQ("name\u20ac", GET_TRACE_OBJECT(1)->name); + CHECK_EQ(1, GET_TRACE_OBJECT(1)->num_args); + } +} -- cgit v1.2.3