2015-02-06 12:07:48 +00:00
|
|
|
// 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.
|
|
|
|
|
2017-08-11 11:22:28 +00:00
|
|
|
#ifndef V8_TEST_CCTEST_TEST_API_H_
|
|
|
|
#define V8_TEST_CCTEST_TEST_API_H_
|
|
|
|
|
2015-02-06 12:07:48 +00:00
|
|
|
#include "src/v8.h"
|
|
|
|
|
2016-09-01 12:01:33 +00:00
|
|
|
#include "src/api.h"
|
2015-02-06 12:07:48 +00:00
|
|
|
#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());
|
2016-06-06 12:58:10 +00:00
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(t.GetIsolate());
|
2015-02-06 12:07:48 +00:00
|
|
|
CHECK_EQ(t.GetIsolate(), rv.GetIsolate());
|
2016-06-06 12:58:10 +00:00
|
|
|
CHECK((*o)->IsTheHole(isolate) || (*o)->IsUndefined(isolate));
|
2015-02-06 12:07:48 +00:00
|
|
|
// Verify reset
|
2016-06-06 12:58:10 +00:00
|
|
|
bool is_runtime = (*o)->IsTheHole(isolate);
|
2016-04-12 09:33:13 +00:00
|
|
|
if (is_runtime) {
|
|
|
|
CHECK(rv.Get()->IsUndefined());
|
|
|
|
} else {
|
|
|
|
i::Handle<i::Object> v = v8::Utils::OpenHandle(*rv.Get());
|
|
|
|
CHECK_EQ(*v, *o);
|
|
|
|
}
|
2015-02-06 12:07:48 +00:00
|
|
|
rv.Set(true);
|
2016-06-06 12:58:10 +00:00
|
|
|
CHECK(!(*o)->IsTheHole(isolate) && !(*o)->IsUndefined(isolate));
|
2015-09-25 14:35:20 +00:00
|
|
|
rv.Set(v8::Local<v8::Object>());
|
2016-06-06 12:58:10 +00:00
|
|
|
CHECK((*o)->IsTheHole(isolate) || (*o)->IsUndefined(isolate));
|
2016-06-14 10:08:44 +00:00
|
|
|
CHECK_EQ(is_runtime, (*o)->IsTheHole(isolate));
|
2015-02-06 12:07:48 +00:00
|
|
|
// If CPU profiler is active check that when API callback is invoked
|
|
|
|
// VMState is set to EXTERNAL.
|
2016-06-09 05:23:34 +00:00
|
|
|
if (isolate->is_profiling()) {
|
2015-02-06 12:07:48 +00:00
|
|
|
CHECK_EQ(v8::EXTERNAL, isolate->current_vm_state());
|
|
|
|
CHECK(isolate->external_callback_scope());
|
|
|
|
CHECK_EQ(callback, isolate->external_callback_scope()->callback());
|
|
|
|
}
|
|
|
|
}
|
2017-08-11 11:22:28 +00:00
|
|
|
|
|
|
|
#endif // V8_TEST_CCTEST_TEST_API_H_
|