Line data Source code
1 : // 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 : #ifndef V8_TEST_CCTEST_TEST_API_H_
6 : #define V8_TEST_CCTEST_TEST_API_H_
7 :
8 : #include "src/v8.h"
9 :
10 : #include "src/api.h"
11 : #include "src/isolate.h"
12 : #include "src/vm-state.h"
13 : #include "test/cctest/cctest.h"
14 :
15 : template <typename T>
16 6591 : static void CheckReturnValue(const T& t, i::Address callback) {
17 : v8::ReturnValue<v8::Value> rv = t.GetReturnValue();
18 : i::FullObjectSlot o(*reinterpret_cast<i::Address*>(&rv));
19 6591 : CHECK_EQ(CcTest::isolate(), t.GetIsolate());
20 : i::Isolate* isolate = reinterpret_cast<i::Isolate*>(t.GetIsolate());
21 6591 : CHECK_EQ(t.GetIsolate(), rv.GetIsolate());
22 6949 : CHECK((*o)->IsTheHole(isolate) || (*o)->IsUndefined(isolate));
23 : // Verify reset
24 : bool is_runtime = (*o)->IsTheHole(isolate);
25 6591 : if (is_runtime) {
26 6233 : CHECK(rv.Get()->IsUndefined());
27 : } else {
28 : i::Handle<i::Object> v = v8::Utils::OpenHandle(*rv.Get());
29 358 : CHECK_EQ(*v, *o);
30 : }
31 : rv.Set(true);
32 13182 : CHECK(!(*o)->IsTheHole(isolate) && !(*o)->IsUndefined(isolate));
33 : rv.Set(v8::Local<v8::Object>());
34 6949 : CHECK((*o)->IsTheHole(isolate) || (*o)->IsUndefined(isolate));
35 6591 : CHECK_EQ(is_runtime, (*o)->IsTheHole(isolate));
36 : // If CPU profiler is active check that when API callback is invoked
37 : // VMState is set to EXTERNAL.
38 6591 : if (isolate->is_profiling()) {
39 2595 : CHECK_EQ(v8::EXTERNAL, isolate->current_vm_state());
40 2595 : CHECK(isolate->external_callback_scope());
41 2595 : CHECK_EQ(callback, isolate->external_callback_scope()->callback());
42 : }
43 6591 : }
44 :
45 : #endif // V8_TEST_CCTEST_TEST_API_H_
|