Commit 6526c6dd authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[RCS] Add explicit tests for function callbacks

This CL adds a very crude unittest to check that RuntimeCallStats work
correctly with api callbacks present. This currently doesn't check that
all parent timers (namely FunctionCallback) are handled properly.

Drive-by-Fix:
- Use Microseconds for all RCS timer tests
- Add TestWithContext::SetGlobalProperty helper
- Use explicit v8:: prefix in test-utils.{h,cc}

Change-Id: I054e78abca0b87a3b9e07d3b06cccdad15403bae
Reviewed-on: https://chromium-review.googlesource.com/766429
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49348}
parent ebe6d7a9
......@@ -683,6 +683,7 @@ void Accessors::FunctionLengthGetter(
v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
RuntimeCallTimerScope timer(isolate, &RuntimeCallStats::FunctionLengthGetter);
HandleScope scope(isolate);
Handle<JSFunction> function =
Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
......
......@@ -527,6 +527,11 @@ bool RuntimeCallStats::IsCalledOnTheSameThread() {
return true;
}
void RuntimeCallStats::Print() {
OFStream os(stdout);
Print(os);
}
void RuntimeCallStats::Print(std::ostream& os) {
RuntimeCallStatEntries entries;
if (current_timer_.Value() != nullptr) {
......
......@@ -803,6 +803,7 @@ class RuntimeCallTimer final {
V(FunctionCallback) \
V(FunctionPrototypeGetter) \
V(FunctionPrototypeSetter) \
V(FunctionLengthGetter) \
V(GC_Custom_AllAvailableGarbage) \
V(GC_Custom_IncrementalMarkingObserver) \
V(GC_Custom_SlowAllocateRaw) \
......@@ -956,6 +957,7 @@ class RuntimeCallStats final : public ZoneObject {
// Add all entries from another stats object.
void Add(RuntimeCallStats* other);
V8_EXPORT_PRIVATE void Print(std::ostream& os);
V8_EXPORT_PRIVATE void Print();
V8_NOINLINE void Dump(v8::tracing::TracedValue* value);
ThreadId thread_id() const { return thread_id_; }
......
......@@ -3033,8 +3033,7 @@ void Isolate::DumpAndResetStats() {
turbo_statistics_ = nullptr;
if (V8_UNLIKELY(FLAG_runtime_stats ==
v8::tracing::TracingCategoryObserver::ENABLED_BY_NATIVE)) {
OFStream os(stdout);
counters()->runtime_call_stats()->Print(os);
counters()->runtime_call_stats()->Print();
counters()->runtime_call_stats()->Reset();
}
}
......
This diff is collapsed.
......@@ -68,6 +68,17 @@ TestWithContext::TestWithContext()
TestWithContext::~TestWithContext() {}
void TestWithContext::SetGlobalProperty(const char* name,
v8::Local<v8::Value> value) {
v8::Local<v8::String> property_name =
v8::String::NewFromUtf8(v8_isolate(), name, v8::NewStringType::kNormal)
.ToLocalChecked();
CHECK(v8_context()
->Global()
->Set(v8_context(), property_name, value)
.FromJust());
}
namespace internal {
TestWithIsolate::~TestWithIsolate() {}
......
......@@ -29,7 +29,9 @@ class TestWithIsolate : public virtual ::testing::Test {
TestWithIsolate();
virtual ~TestWithIsolate();
Isolate* isolate() const { return isolate_; }
v8::Isolate* isolate() const { return v8_isolate(); }
v8::Isolate* v8_isolate() const { return isolate_; }
v8::internal::Isolate* i_isolate() const {
return reinterpret_cast<v8::internal::Isolate*>(isolate());
......@@ -42,25 +44,28 @@ class TestWithIsolate : public virtual ::testing::Test {
private:
static v8::ArrayBuffer::Allocator* array_buffer_allocator_;
static Isolate* isolate_;
Isolate::Scope isolate_scope_;
HandleScope handle_scope_;
static v8::Isolate* isolate_;
v8::Isolate::Scope isolate_scope_;
v8::HandleScope handle_scope_;
DISALLOW_COPY_AND_ASSIGN(TestWithIsolate);
};
// Use v8::internal::TestWithNativeContext if you are testing internals,
// aka. directly work with Handles.
class TestWithContext : public virtual TestWithIsolate {
class TestWithContext : public virtual v8::TestWithIsolate {
public:
TestWithContext();
virtual ~TestWithContext();
const Local<Context>& context() const { return context_; }
const Local<Context>& context() const { return v8_context(); }
const Local<Context>& v8_context() const { return context_; }
void SetGlobalProperty(const char* name, v8::Local<v8::Value> value);
private:
Local<Context> context_;
Context::Scope context_scope_;
v8::Context::Scope context_scope_;
DISALLOW_COPY_AND_ASSIGN(TestWithContext);
};
......@@ -77,9 +82,7 @@ class TestWithIsolate : public virtual ::v8::TestWithIsolate {
virtual ~TestWithIsolate();
Factory* factory() const;
Isolate* isolate() const {
return reinterpret_cast<Isolate*>(::v8::TestWithIsolate::isolate());
}
Isolate* isolate() const { return i_isolate(); }
template <typename T = Object>
Handle<T> RunJS(const char* source) {
Handle<Object> result =
......
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