blob: 8887a8a976558d14ac1482b22968f2e2831a8719 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "src/v8.h"
6
7#include "src/isolate.h"
8#include "src/profiler/cpu-profiler.h"
9#include "src/vm-state.h"
10#include "test/cctest/cctest.h"
11
12template <typename T>
13static void CheckReturnValue(const T& t, i::Address callback) {
14 v8::ReturnValue<v8::Value> rv = t.GetReturnValue();
15 i::Object** o = *reinterpret_cast<i::Object***>(&rv);
16 CHECK_EQ(CcTest::isolate(), t.GetIsolate());
17 CHECK_EQ(t.GetIsolate(), rv.GetIsolate());
18 CHECK((*o)->IsTheHole() || (*o)->IsUndefined());
19 // Verify reset
20 bool is_runtime = (*o)->IsTheHole();
Ben Murdochda12d292016-06-02 14:46:10 +010021 if (is_runtime) {
22 CHECK(rv.Get()->IsUndefined());
23 } else {
24 i::Handle<i::Object> v = v8::Utils::OpenHandle(*rv.Get());
25 CHECK_EQ(*v, *o);
26 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000027 rv.Set(true);
28 CHECK(!(*o)->IsTheHole() && !(*o)->IsUndefined());
29 rv.Set(v8::Local<v8::Object>());
30 CHECK((*o)->IsTheHole() || (*o)->IsUndefined());
31 CHECK_EQ(is_runtime, (*o)->IsTheHole());
32 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(t.GetIsolate());
33 // If CPU profiler is active check that when API callback is invoked
34 // VMState is set to EXTERNAL.
35 if (isolate->cpu_profiler()->is_profiling()) {
36 CHECK_EQ(v8::EXTERNAL, isolate->current_vm_state());
37 CHECK(isolate->external_callback_scope());
38 CHECK_EQ(callback, isolate->external_callback_scope()->callback());
39 }
40}