summaryrefslogtreecommitdiff
path: root/deps/v8/test/cctest/test-api.h
blob: 6194a114058542f2af962bfe9b322a4a97f97bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/v8.h"

#include "src/api.h"
#include "src/isolate.h"
#include "src/vm-state.h"
#include "test/cctest/cctest.h"

template <typename T>
static void CheckReturnValue(const T& t, i::Address callback) {
  v8::ReturnValue<v8::Value> rv = t.GetReturnValue();
  i::Object** o = *reinterpret_cast<i::Object***>(&rv);
  CHECK_EQ(CcTest::isolate(), t.GetIsolate());
  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(t.GetIsolate());
  CHECK_EQ(t.GetIsolate(), rv.GetIsolate());
  CHECK((*o)->IsTheHole(isolate) || (*o)->IsUndefined(isolate));
  // Verify reset
  bool is_runtime = (*o)->IsTheHole(isolate);
  if (is_runtime) {
    CHECK(rv.Get()->IsUndefined());
  } else {
    i::Handle<i::Object> v = v8::Utils::OpenHandle(*rv.Get());
    CHECK_EQ(*v, *o);
  }
  rv.Set(true);
  CHECK(!(*o)->IsTheHole(isolate) && !(*o)->IsUndefined(isolate));
  rv.Set(v8::Local<v8::Object>());
  CHECK((*o)->IsTheHole(isolate) || (*o)->IsUndefined(isolate));
  CHECK_EQ(is_runtime, (*o)->IsTheHole(isolate));
  // If CPU profiler is active check that when API callback is invoked
  // VMState is set to EXTERNAL.
  if (isolate->is_profiling()) {
    CHECK_EQ(v8::EXTERNAL, isolate->current_vm_state());
    CHECK(isolate->external_callback_scope());
    CHECK_EQ(callback, isolate->external_callback_scope()->callback());
  }
}