test-api.h 1.56 KB
Newer Older
1 2 3 4
// 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.

5 6 7
#ifndef V8_TEST_CCTEST_TEST_API_H_
#define V8_TEST_CCTEST_TEST_API_H_

8 9
#include "src/v8.h"

10
#include "src/api.h"
11 12 13 14 15 16 17 18 19
#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());
20
  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(t.GetIsolate());
21
  CHECK_EQ(t.GetIsolate(), rv.GetIsolate());
22
  CHECK((*o)->IsTheHole(isolate) || (*o)->IsUndefined(isolate));
23
  // Verify reset
24
  bool is_runtime = (*o)->IsTheHole(isolate);
25 26 27 28 29 30
  if (is_runtime) {
    CHECK(rv.Get()->IsUndefined());
  } else {
    i::Handle<i::Object> v = v8::Utils::OpenHandle(*rv.Get());
    CHECK_EQ(*v, *o);
  }
31
  rv.Set(true);
32
  CHECK(!(*o)->IsTheHole(isolate) && !(*o)->IsUndefined(isolate));
vogelheim's avatar
vogelheim committed
33
  rv.Set(v8::Local<v8::Object>());
34
  CHECK((*o)->IsTheHole(isolate) || (*o)->IsUndefined(isolate));
35
  CHECK_EQ(is_runtime, (*o)->IsTheHole(isolate));
36 37
  // If CPU profiler is active check that when API callback is invoked
  // VMState is set to EXTERNAL.
38
  if (isolate->is_profiling()) {
39 40 41 42 43
    CHECK_EQ(v8::EXTERNAL, isolate->current_vm_state());
    CHECK(isolate->external_callback_scope());
    CHECK_EQ(callback, isolate->external_callback_scope()->callback());
  }
}
44 45

#endif  // V8_TEST_CCTEST_TEST_API_H_