blob: f9a335a7f4ccc686b5811a720b258f9b488f0624 [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"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include "src/vm-state.h"
9#include "test/cctest/cctest.h"
10
11template <typename T>
12static void CheckReturnValue(const T& t, i::Address callback) {
13 v8::ReturnValue<v8::Value> rv = t.GetReturnValue();
14 i::Object** o = *reinterpret_cast<i::Object***>(&rv);
15 CHECK_EQ(CcTest::isolate(), t.GetIsolate());
Ben Murdoch61f157c2016-09-16 13:49:30 +010016 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(t.GetIsolate());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000017 CHECK_EQ(t.GetIsolate(), rv.GetIsolate());
Ben Murdoch61f157c2016-09-16 13:49:30 +010018 CHECK((*o)->IsTheHole(isolate) || (*o)->IsUndefined(isolate));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000019 // Verify reset
Ben Murdoch61f157c2016-09-16 13:49:30 +010020 bool is_runtime = (*o)->IsTheHole(isolate);
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);
Ben Murdoch61f157c2016-09-16 13:49:30 +010028 CHECK(!(*o)->IsTheHole(isolate) && !(*o)->IsUndefined(isolate));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000029 rv.Set(v8::Local<v8::Object>());
Ben Murdoch61f157c2016-09-16 13:49:30 +010030 CHECK((*o)->IsTheHole(isolate) || (*o)->IsUndefined(isolate));
31 CHECK_EQ(is_runtime, (*o)->IsTheHole(isolate));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000032 // If CPU profiler is active check that when API callback is invoked
33 // VMState is set to EXTERNAL.
Ben Murdoch61f157c2016-09-16 13:49:30 +010034 if (isolate->is_profiling()) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000035 CHECK_EQ(v8::EXTERNAL, isolate->current_vm_state());
36 CHECK(isolate->external_callback_scope());
37 CHECK_EQ(callback, isolate->external_callback_scope()->callback());
38 }
39}