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

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