void Intersect(const EnumSet& set) { bits_ &= set.bits_; }
T ToIntegral() const { return bits_; }
bool operator==(const EnumSet& set) { return bits_ == set.bits_; }
+ EnumSet<E, T> operator|(const EnumSet& set) const {
+ return EnumSet<E, T>(bits_ | set.bits_);
+ }
private:
T Mask(E element) const {
}
+v8::Persistent<v8::Context> CcTest::context_;
+
+
+void CcTest::InitializeVM(CcTestExtensionFlags extensions) {
+ const char* extension_names[kMaxExtensions];
+ int extension_count = 0;
+#define CHECK_EXTENSION_FLAG(Name, Id) \
+ if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id;
+ EXTENSION_LIST(CHECK_EXTENSION_FLAG)
+#undef CHECK_EXTENSION_FLAG
+ if (context_.IsEmpty()) {
+ v8::ExtensionConfiguration config(extension_count, extension_names);
+ context_ = v8::Context::New(&config);
+ }
+ context_->Enter();
+}
+
+
static void PrintTestList(CcTest* current) {
if (current == NULL) return;
PrintTestList(current->prev());
v8::Isolate* CcTest::default_isolate_;
+
int main(int argc, char* argv[]) {
v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
CcTest::set_default_isolate(v8::Isolate::GetCurrent());
static void Test##Name()
#endif
+#define EXTENSION_LIST(V) \
+ V(GC_EXTENSION, "v8/gc") \
+ V(PRINT_EXTENSION, "v8/print") \
+ V(TRACE_EXTENSION, "v8/trace")
+
+#define DEFINE_EXTENSION_ID(Name, Ident) Name##_ID,
+enum CcTestExtensionIds {
+ EXTENSION_LIST(DEFINE_EXTENSION_ID)
+ kMaxExtensions
+};
+#undef DEFINE_EXTENSION_ID
+
+typedef v8::internal::EnumSet<CcTestExtensionIds> CcTestExtensionFlags;
+#define DEFINE_EXTENSION_FLAG(Name, Ident) \
+ static const CcTestExtensionFlags Name(1 << Name##_ID);
+ static const CcTestExtensionFlags NO_EXTENSIONS(0);
+ static const CcTestExtensionFlags ALL_EXTENSIONS((1 << kMaxExtensions) - 1);
+ EXTENSION_LIST(DEFINE_EXTENSION_FLAG)
+#undef DEFINE_EXTENSION_FLAG
+
class CcTest {
public:
typedef void (TestFunction)();
default_isolate_ = default_isolate;
}
static v8::Isolate* default_isolate() { return default_isolate_; }
+ static v8::Isolate* isolate() { return context_->GetIsolate(); }
+ static v8::Handle<v8::Context> env() { return context_; }
+
+ // Helper function to initialize the VM.
+ static void InitializeVM(CcTestExtensionFlags extensions = NO_EXTENSIONS);
private:
TestFunction* callback_;
const char* name_;
const char* dependency_;
bool enabled_;
- static CcTest* last_;
CcTest* prev_;
+ static CcTest* last_;
static v8::Isolate* default_isolate_;
+ static v8::Persistent<v8::Context> context_;
};
// Switches between all the Api tests using the threading support.
typedef Object* (*F4)(void* p0, void* p1, int p2, int p3, int p4);
-static v8::Persistent<v8::Context> env;
-
-
-static void InitializeVM() {
- if (env.IsEmpty()) {
- env = v8::Context::New();
- }
-}
-
-
#define __ assm.
TEST(0) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(1) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(2) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(3) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(4) {
// Test the VFP floating point instructions.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(5) {
// Test the ARMv7 bitfield instructions.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(6) {
// Test saturating instructions.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
double value,
int expected,
bool expected_exception = false) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(8) {
// Test VFP multi load/store with ia_w.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(9) {
// Test VFP multi load/store with ia.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(10) {
// Test VFP multi load/store with db_w.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(11) {
// Test instructions using the carry flag.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(12) {
// Test chaining of label usages within instructions (issue 1644).
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(13) {
// Test VFP instructions using registers d16-d31.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
typedef int (*F2)(int x, int y);
-static v8::Persistent<v8::Context> env;
-
-
-static void InitializeVM() {
- if (env.IsEmpty()) {
- env = v8::Context::New();
- }
-}
-
-
#define __ assm.
TEST(AssemblerIa320) {
- InitializeVM();
- Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
+ CcTest::InitializeVM();
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
HandleScope scope(isolate);
v8::internal::byte buffer[256];
TEST(AssemblerIa321) {
- InitializeVM();
- Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
+ CcTest::InitializeVM();
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
HandleScope scope(isolate);
v8::internal::byte buffer[256];
TEST(AssemblerIa322) {
- InitializeVM();
- Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
+ CcTest::InitializeVM();
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
HandleScope scope(isolate);
v8::internal::byte buffer[256];
typedef int (*F3)(float x);
TEST(AssemblerIa323) {
- InitializeVM();
+ CcTest::InitializeVM();
if (!CpuFeatures::IsSupported(SSE2)) return;
- Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
HandleScope scope(isolate);
v8::internal::byte buffer[256];
typedef int (*F4)(double x);
TEST(AssemblerIa324) {
- InitializeVM();
+ CcTest::InitializeVM();
if (!CpuFeatures::IsSupported(SSE2)) return;
- Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
HandleScope scope(isolate);
v8::internal::byte buffer[256];
static int baz = 42;
TEST(AssemblerIa325) {
- InitializeVM();
- Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
+ CcTest::InitializeVM();
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
HandleScope scope(isolate);
v8::internal::byte buffer[256];
typedef double (*F5)(double x, double y);
TEST(AssemblerIa326) {
- InitializeVM();
+ CcTest::InitializeVM();
if (!CpuFeatures::IsSupported(SSE2)) return;
- Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
HandleScope scope(isolate);
v8::internal::byte buffer[256];
Assembler assm(isolate, buffer, sizeof buffer);
typedef double (*F6)(int x);
TEST(AssemblerIa328) {
- InitializeVM();
+ CcTest::InitializeVM();
if (!CpuFeatures::IsSupported(SSE2)) return;
- Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
HandleScope scope(isolate);
v8::internal::byte buffer[256];
Assembler assm(isolate, buffer, sizeof buffer);
typedef int (*F7)(double x, double y);
TEST(AssemblerIa329) {
- InitializeVM();
- Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
+ CcTest::InitializeVM();
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
HandleScope scope(isolate);
v8::internal::byte buffer[256];
MacroAssembler assm(isolate, buffer, sizeof buffer);
TEST(AssemblerIa3210) {
// Test chaining of label usages within instructions (issue 1644).
- InitializeVM();
- Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
+ CcTest::InitializeVM();
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
HandleScope scope(isolate);
Assembler assm(isolate, NULL, 0);
TEST(AssemblerMultiByteNop) {
- InitializeVM();
- Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
+ CcTest::InitializeVM();
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
HandleScope scope(isolate);
v8::internal::byte buffer[1024];
Assembler assm(isolate, buffer, sizeof(buffer));
typedef Object* (*F3)(void* p, int p1, int p2, int p3, int p4);
-static v8::Persistent<v8::Context> env;
-
-
-static void InitializeVM() {
- // Disable compilation of natives.
- FLAG_disable_native_files = true;
-
- if (env.IsEmpty()) {
- env = v8::Context::New();
- }
-}
-
-
#define __ assm.
TEST(MIPS0) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS1) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS2) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS3) {
// Test floating point instructions.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS4) {
// Test moves between floating point and integer registers.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS5) {
// Test conversions between doubles and integers.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS6) {
// Test simple memory loads and stores.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS7) {
// Test floating point compare and branch instructions.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS8) {
// Test ROTR and ROTRV instructions.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS9) {
// Test BRANCH improvements.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS10) {
// Test conversions between doubles and long integers.
// Test hos the long ints map to FP regs pairs.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS11) {
// Test LWL, LWR, SWL and SWR instructions.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS12) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS13) {
// Test Cvt_d_uw and Trunc_uw_d macros.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS14) {
// Test round, floor, ceil, trunc, cvt.
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
TEST(MIPS15) {
// Test chaining of label usages within instructions (issue 1644).
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);
Assembler assm(isolate, NULL, 0);
#define __ assm.
-static v8::Persistent<v8::Context> env;
-
-
-static void InitializeVM() {
- if (env.IsEmpty()) {
- env = v8::Context::New();
- }
-}
-
-
TEST(AssemblerX64ReturnOperation) {
OS::SetUp();
// Allocate an executable page of memory.
TEST(AssemblerX64LabelChaining) {
// Test chaining of label usages within instructions (issue 1644).
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
Assembler assm(Isolate::Current(), NULL, 0);
Label target;
TEST(AssemblerMultiByteNop) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::internal::byte buffer[1024];
Isolate* isolate = Isolate::Current();
Assembler assm(isolate, buffer, sizeof(buffer));
using namespace v8::internal;
-static v8::Persistent<v8::Context> env;
-
// --- P r i n t E x t e n s i o n ---
class PrintExtension : public v8::Extension {
v8::DeclareExtension kPrintExtensionDeclaration(&kPrintExtension);
-static void InitializeVM() {
- if (env.IsEmpty()) {
- const char* extensions[] = { "v8/print", "v8/gc" };
- v8::ExtensionConfiguration config(2, extensions);
- env = v8::Context::New(&config);
- }
- env->Enter();
-}
-
-
static MaybeObject* GetGlobalProperty(const char* name) {
Handle<String> internalized_name = FACTORY->InternalizeUtf8String(name);
return Isolate::Current()->context()->global_object()->GetProperty(
TEST(Inc) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
CHECK_EQ(4.0, Inc(3));
}
TEST(Add) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
CHECK_EQ(5.0, Add(2, 3));
}
TEST(Abs) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
CHECK_EQ(3.0, Abs(-3));
}
TEST(Sum) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
CHECK_EQ(5050.0, Sum(100));
}
TEST(Print) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM(PRINT_EXTENSION);
+ v8::HandleScope scope(CcTest::isolate());
const char* source = "for (n = 0; n < 100; ++n) print(n, 1, 2);";
Handle<JSFunction> fun = Compile(source);
if (fun.is_null()) return;
// The following test method stems from my coding efforts today. It
// tests all the functionality I have added to the compiler today
TEST(Stuff) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
const char* source =
"r = 0;\n"
"a = new Object;\n"
TEST(UncaughtThrow) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
const char* source = "throw 42;";
Handle<JSFunction> fun = Compile(source);
// | JS |
// | C-to-JS |
TEST(C2JSFrames) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM(PRINT_EXTENSION | GC_EXTENSION);
+ v8::HandleScope scope(CcTest::isolate());
const char* source = "function foo(a) { gc(), print(a); }";
// Regression 236. Calling InitLineEnds on a Script with undefined
// source resulted in crash.
TEST(Regression236) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
Handle<Script> script = FACTORY->NewScript(FACTORY->empty_string());
script->set_source(HEAP->undefined_value());
TEST(GetScriptLineNumber) {
- LocalContext env;
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
const char function_f[] = "function f() {}";
const int max_rows = 1000;
v8::Handle<v8::String> script_body = v8::String::New(buffer.start());
v8::Script::Compile(script_body, &origin)->Run();
v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
- env->Global()->Get(v8::String::New("f")));
+ CcTest::env()->Global()->Get(v8::String::New("f")));
CHECK_EQ(i, f->GetScriptLineNumber());
}
}
// FastNewClosureStub that is baked into the snapshot is incorrect.
if (!FLAG_cache_optimized_code) return;
FLAG_allow_natives_syntax = true;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
for (int i = 0; i < 10; i++) {
LocalContext env;
env->Global()->Set(v8::String::New("x"), v8::Integer::New(i));
TEST(SplitConstantsInFullCompiler) {
- LocalContext env;
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
CompileRun("function f() { a = 12345678 }; f();");
- CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f"));
+ CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f"));
CompileRun("function f(x) { a = 12345678 + x}; f(1);");
- CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f"));
+ CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f"));
CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);");
- CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f"));
+ CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f"));
CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);");
- CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f"));
+ CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f"));
}
#endif
processor.Join();
}
-static v8::Persistent<v8::Context> env;
-
-static void InitializeVM() {
- if (env.IsEmpty()) env = v8::Context::New();
- v8::HandleScope scope(env->GetIsolate());
- env->Enter();
-}
-
static inline i::Address ToAddress(int n) {
return reinterpret_cast<i::Address>(n);
}
} // namespace
TEST(CodeEvents) {
- InitializeVM();
+ CcTest::InitializeVM();
i::Isolate* isolate = i::Isolate::Current();
i::Heap* heap = isolate->heap();
i::Factory* factory = isolate->factory();
// http://crbug/51594
// This test must not crash.
TEST(CrashIfStoppingLastNonExistentProfile) {
- InitializeVM();
+ CcTest::InitializeVM();
TestSetup test_setup;
CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
profiler->StartProfiling("1");
TEST(DeleteAllCpuProfiles) {
- InitializeVM();
+ CcTest::InitializeVM();
TestSetup test_setup;
CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
CHECK_EQ(0, profiler->GetProfilesCount());
using namespace v8::internal;
-static v8::Persistent<v8::Context> env;
-
-static void InitializeVM() {
- if (env.IsEmpty()) {
- env = v8::Context::New();
- }
-}
-
-
bool DisassembleAndCompare(byte* pc, const char* compare_string) {
disasm::NameConverter converter;
disasm::Disassembler disasm(converter);
// disassembler. Declare the variables and allocate the data structures used
// in the rest of the macros.
#define SET_UP() \
- InitializeVM(); \
+ CcTest::InitializeVM(); \
Isolate* isolate = Isolate::Current(); \
HandleScope scope(isolate); \
byte *buffer = reinterpret_cast<byte*>(malloc(4*1024)); \
using namespace v8::internal;
-static v8::Persistent<v8::Context> env;
-
-static void InitializeVM() {
- if (env.IsEmpty()) {
- env = v8::Context::New();
- }
-}
-
#define __ assm.
TEST(DisasmIa320) {
- InitializeVM();
- Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
+ CcTest::InitializeVM();
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
HandleScope scope(isolate);
v8::internal::byte buffer[2048];
Assembler assm(isolate, buffer, sizeof buffer);
using namespace v8::internal;
-static v8::Persistent<v8::Context> env;
-
-static void InitializeVM() {
- // Disable compilation of natives.
- FLAG_disable_native_files = true;
- if (env.IsEmpty()) {
- env = v8::Context::New();
- }
-}
-
-
bool DisassembleAndCompare(byte* pc, const char* compare_string) {
disasm::NameConverter converter;
disasm::Disassembler disasm(converter);
// disassembler. Declare the variables and allocate the data structures used
// in the rest of the macros.
#define SET_UP() \
- InitializeVM(); \
+ CcTest::InitializeVM(); \
Isolate* isolate = Isolate::Current(); \
HandleScope scope(isolate); \
byte *buffer = reinterpret_cast<byte*>(malloc(4*1024)); \
using namespace v8::internal;
-static v8::Persistent<v8::Context> env;
-
-static void InitializeVM() {
- if (env.IsEmpty()) {
- env = v8::Context::New();
- }
-}
-
#define __ assm.
TEST(DisasmX64) {
- InitializeVM();
+ CcTest::InitializeVM();
v8::HandleScope scope;
v8::internal::byte buffer[2048];
Assembler assm(Isolate::Current(), buffer, sizeof buffer);
using ::v8::internal::String;
-static v8::Persistent<v8::Context> env;
-
-
-static void InitializeVM() {
- if (env.IsEmpty()) {
- env = v8::Context::New();
- }
- env->Enter();
-}
-
-
static void CheckFunctionName(v8::Handle<v8::Script> script,
const char* func_pos_src,
const char* ref_inferred_name) {
TEST(GlobalProperty) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"fun1 = function() { return 1; }\n"
TEST(GlobalVar) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"var fun1 = function() { return 1; }\n"
TEST(LocalVar) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"function outer() {\n"
TEST(InConstructor) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"function MyClass() {\n"
TEST(Factory) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"function createMyObj() {\n"
TEST(Static) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"function MyClass() {}\n"
TEST(Prototype) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"function MyClass() {}\n"
TEST(ObjectLiteral) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"function MyClass() {}\n"
TEST(AsParameter) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"function f1(a) { return a(); }\n"
TEST(MultipleFuncsConditional) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"fun1 = 0 ?\n"
TEST(MultipleFuncsInLiteral) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"function MyClass() {}\n"
// See http://code.google.com/p/v8/issues/detail?id=380
TEST(Issue380) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"function a() {\n"
TEST(MultipleAssignments) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"var fun1 = fun2 = function () { return 1; }\n"
TEST(AsConstructorParameter) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"function Foo() {}\n"
TEST(FactoryHashmap) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"function createMyObj() {\n"
TEST(FactoryHashmapVariable) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"function createMyObj() {\n"
TEST(FactoryHashmapConditional) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"function createMyObj() {\n"
TEST(GlobalAssignmentAndCall) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"var Foo = function() {\n"
TEST(AssignmentAndCall) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"(function Enclosing() {\n"
TEST(MethodAssignmentInAnonymousFunctionCall) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"(function () {\n"
TEST(ReturnAnonymousFunction) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Script> script = Compile(
"(function() {\n"
using namespace v8::internal;
-static v8::Persistent<v8::Context> env;
-
-static void InitializeVM() {
- if (env.IsEmpty()) env = v8::Context::New();
- env->Enter();
-}
-
// Go through all incremental marking steps in one swoop.
static void SimulateIncrementalMarking() {
TEST(HeapMaps) {
- InitializeVM();
+ CcTest::InitializeVM();
CheckMap(HEAP->meta_map(), MAP_TYPE, Map::kSize);
CheckMap(HEAP->heap_number_map(), HEAP_NUMBER_TYPE, HeapNumber::kSize);
CheckMap(HEAP->fixed_array_map(), FIXED_ARRAY_TYPE, kVariableSizeSentinel);
TEST(HeapObjects) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
TEST(Tagging) {
- InitializeVM();
+ CcTest::InitializeVM();
int request = 24;
CHECK_EQ(request, static_cast<int>(OBJECT_POINTER_ALIGN(request)));
CHECK(Smi::FromInt(42)->IsSmi());
TEST(GarbageCollection) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
Factory* factory = isolate->factory();
TEST(String) {
- InitializeVM();
- Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
+ CcTest::InitializeVM();
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
VerifyStringAllocation(isolate, "a");
VerifyStringAllocation(isolate, "ab");
TEST(LocalHandles) {
- InitializeVM();
+ CcTest::InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(CcTest::isolate());
const char* name = "Kasper the spunky";
Handle<String> string = FACTORY->NewStringFromAscii(CStrVector(name));
CHECK_EQ(StrLength(name), string->length());
TEST(GlobalHandles) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
Factory* factory = isolate->factory();
TEST(WeakGlobalHandlesScavenge) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
Factory* factory = isolate->factory();
TEST(WeakGlobalHandlesMark) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
Factory* factory = isolate->factory();
TEST(DeleteWeakGlobalHandle) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
Factory* factory = isolate->factory();
TEST(StringTable) {
- InitializeVM();
+ CcTest::InitializeVM();
CheckInternalizedStrings(not_so_random_string_table);
CheckInternalizedStrings(not_so_random_string_table);
TEST(FunctionAllocation) {
- InitializeVM();
+ CcTest::InitializeVM();
- v8::HandleScope sc(env->GetIsolate());
+ v8::HandleScope sc(CcTest::isolate());
Handle<String> name = FACTORY->InternalizeUtf8String("theFunction");
Handle<JSFunction> function =
FACTORY->NewFunction(name, FACTORY->undefined_value());
TEST(ObjectProperties) {
- InitializeVM();
+ CcTest::InitializeVM();
- v8::HandleScope sc(env->GetIsolate());
+ v8::HandleScope sc(CcTest::isolate());
String* object_string = String::cast(HEAP->Object_string());
Object* raw_object = Isolate::Current()->context()->global_object()->
GetProperty(object_string)->ToObjectChecked();
TEST(JSObjectMaps) {
- InitializeVM();
+ CcTest::InitializeVM();
- v8::HandleScope sc(env->GetIsolate());
+ v8::HandleScope sc(CcTest::isolate());
Handle<String> name = FACTORY->InternalizeUtf8String("theFunction");
Handle<JSFunction> function =
FACTORY->NewFunction(name, FACTORY->undefined_value());
TEST(JSArray) {
- InitializeVM();
+ CcTest::InitializeVM();
- v8::HandleScope sc(env->GetIsolate());
+ v8::HandleScope sc(CcTest::isolate());
Handle<String> name = FACTORY->InternalizeUtf8String("Array");
Object* raw_object = Isolate::Current()->context()->global_object()->
GetProperty(*name)->ToObjectChecked();
TEST(JSObjectCopy) {
- InitializeVM();
+ CcTest::InitializeVM();
- v8::HandleScope sc(env->GetIsolate());
+ v8::HandleScope sc(CcTest::isolate());
String* object_string = String::cast(HEAP->Object_string());
Object* raw_object = Isolate::Current()->context()->global_object()->
GetProperty(object_string)->ToObjectChecked();
TEST(StringAllocation) {
- InitializeVM();
+ CcTest::InitializeVM();
const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 };
for (int length = 0; length < 100; length++) {
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(CcTest::isolate());
char* non_ascii = NewArray<char>(3 * length + 1);
char* ascii = NewArray<char>(length + 1);
non_ascii[3 * length] = 0;
TEST(Iteration) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
// Array of objects to scan haep for.
const int objs_count = 6;
TEST(EmptyHandleEscapeFrom) {
- InitializeVM();
+ CcTest::InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(CcTest::isolate());
Handle<JSObject> runaway;
{
- v8::HandleScope nested(env->GetIsolate());
+ v8::HandleScope nested(CcTest::isolate());
Handle<JSObject> empty;
runaway = empty.EscapeFrom(&nested);
}
TEST(Regression39128) {
// Test case for crbug.com/39128.
- InitializeVM();
+ CcTest::InitializeVM();
// Increase the chance of 'bump-the-pointer' allocation in old space.
HEAP->CollectAllGarbage(Heap::kNoGCFlags);
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(CcTest::isolate());
// The plan: create JSObject which references objects in new space.
// Then clone this object (forcing it to go into old space) and check
// If we do not flush code this test is invalid.
if (!FLAG_flush_code) return;
i::FLAG_allow_natives_syntax = true;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
const char* source = "function foo() {"
" var x = 42;"
" var y = 42;"
Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo");
// This compile will add the code to the compilation cache.
- { v8::HandleScope scope(env->GetIsolate());
+ { v8::HandleScope scope(CcTest::isolate());
CompileRun(source);
}
// If we do not flush code this test is invalid.
if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return;
i::FLAG_allow_natives_syntax = true;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
const char* source = "function foo() {"
" var x = 42;"
" var y = 42;"
Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo");
// This compile will add the code to the compilation cache.
- { v8::HandleScope scope(env->GetIsolate());
+ { v8::HandleScope scope(CcTest::isolate());
CompileRun(source);
}
CHECK(!function->is_compiled() || function->IsOptimized());
// This compile will compile the function again.
- { v8::HandleScope scope(env->GetIsolate());
+ { v8::HandleScope scope(CcTest::isolate());
CompileRun("foo();");
}
// Force optimization while incremental marking is active and while
// the function is enqueued as a candidate.
- { v8::HandleScope scope(env->GetIsolate());
+ { v8::HandleScope scope(CcTest::isolate());
CompileRun("%OptimizeFunctionOnNextCall(foo); foo();");
}
// If we do not flush code this test is invalid.
if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return;
i::FLAG_allow_natives_syntax = true;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
const char* source = "var foo = function() {"
" var x = 42;"
" var y = 42;"
HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
// This compile will add the code to the compilation cache.
- { v8::HandleScope scope(env->GetIsolate());
+ { v8::HandleScope scope(CcTest::isolate());
CompileRun(source);
}
CHECK(function2->shared()->is_compiled());
// Clear references to functions so that one of them can die.
- { v8::HandleScope scope(env->GetIsolate());
+ { v8::HandleScope scope(CcTest::isolate());
CompileRun("foo = 0; bar = 0;");
}
// If we do not flush code this test is invalid.
if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return;
i::FLAG_allow_natives_syntax = true;
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(CcTest::isolate());
const char* source = "function foo() {"
" var x = 42;"
" var y = 42;"
Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo");
// This compile will add the code to the compilation cache.
- { v8::HandleScope scope(env->GetIsolate());
+ { v8::HandleScope scope(CcTest::isolate());
CompileRun(source);
}
#endif // ENABLE_DEBUGGER_SUPPORT
// Force optimization now that code flushing is disabled.
- { v8::HandleScope scope(env->GetIsolate());
+ { v8::HandleScope scope(CcTest::isolate());
CompileRun("%OptimizeFunctionOnNextCall(foo); foo();");
}
TEST(TestSizeOfObjectsVsHeapIteratorPrecision) {
- InitializeVM();
+ CcTest::InitializeVM();
HEAP->EnsureHeapIsIterable();
intptr_t size_of_objects_1 = HEAP->SizeOfObjects();
HeapIterator iterator(HEAP);
TEST(GrowAndShrinkNewSpace) {
- InitializeVM();
+ CcTest::InitializeVM();
NewSpace* new_space = HEAP->new_space();
if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize() ||
TEST(CollectingAllAvailableGarbageShrinksNewSpace) {
- InitializeVM();
+ CcTest::InitializeVM();
if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize() ||
HEAP->MaxSemiSpaceSize() == HEAP->InitialSemiSpaceSize()) {
return;
}
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(CcTest::isolate());
NewSpace* new_space = HEAP->new_space();
intptr_t old_capacity, new_capacity;
old_capacity = new_space->Capacity();
i::FLAG_verify_heap = true;
#endif
- InitializeVM();
+ CcTest::InitializeVM();
if (!i::V8::UseCrankshaft()) return;
if (i::FLAG_force_marking_deque_overflows) return;
v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
TEST(PrototypeTransitionClearing) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
CompileRun(
"var base = {};"
i::FLAG_verify_heap = true;
#endif
- InitializeVM();
+ CcTest::InitializeVM();
if (!i::V8::UseCrankshaft()) return;
v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
i::FLAG_verify_heap = true;
#endif
- InitializeVM();
+ CcTest::InitializeVM();
if (!i::V8::UseCrankshaft()) return;
- v8::HandleScope outer_scope(env->GetIsolate());
+ v8::HandleScope outer_scope(CcTest::isolate());
{
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(CcTest::isolate());
CompileRun(
"function f () {"
" var s = 0;"
// Test that HAllocateObject will always return an object in new-space.
TEST(OptimizedAllocationAlwaysInNewSpace) {
i::FLAG_allow_natives_syntax = true;
- InitializeVM();
+ CcTest::InitializeVM();
if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(CcTest::isolate());
SimulateFullSpace(HEAP->new_space());
AlwaysAllocateScope always_allocate;
TEST(OptimizedPretenuringArrayLiterals) {
i::FLAG_allow_natives_syntax = true;
i::FLAG_pretenure_literals = true;
- InitializeVM();
+ CcTest::InitializeVM();
if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(CcTest::isolate());
AlwaysAllocateScope always_allocate;
v8::Local<v8::Value> res = CompileRun(
// Test regular array literals allocation.
TEST(OptimizedAllocationArrayLiterals) {
i::FLAG_allow_natives_syntax = true;
- InitializeVM();
+ CcTest::InitializeVM();
if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return;
if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(CcTest::isolate());
AlwaysAllocateScope always_allocate;
v8::Local<v8::Value> res = CompileRun(
TEST(Regress1465) {
i::FLAG_allow_natives_syntax = true;
i::FLAG_trace_incremental_marking = true;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
static const int transitions_count = 256;
{
TEST(Regress2143a) {
i::FLAG_collect_maps = true;
i::FLAG_incremental_marking = true;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
// Prepare a map transition from the root object together with a yet
// untransitioned root object.
i::FLAG_collect_maps = true;
i::FLAG_incremental_marking = true;
i::FLAG_allow_natives_syntax = true;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
// Prepare a map transition from the root object together with a yet
// untransitioned root object.
// The optimizer can allocate stuff, messing up the test.
i::FLAG_crankshaft = false;
i::FLAG_always_opt = false;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
static const int number_of_test_pages = 20;
// Prepare many pages with low live-bytes count.
TEST(Regress2237) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
Handle<String> slice(HEAP->empty_string());
{
// Generate a parent that lives in new-space.
- v8::HandleScope inner_scope(env->GetIsolate());
+ v8::HandleScope inner_scope(CcTest::isolate());
const char* c = "This text is long enough to trigger sliced strings.";
Handle<String> s = FACTORY->NewStringFromAscii(CStrVector(c));
CHECK(s->IsSeqOneByteString());
#ifdef OBJECT_PRINT
TEST(PrintSharedFunctionInfo) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
const char* source = "f = function() { return 987654321; }\n"
"g = function() { return 123456789; }\n";
CompileRun(source);
TEST(Regress2211) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::String> value = v8_str("val string");
Smi* hash = Smi::FromInt(321);
TEST(IncrementalMarkingClearsTypeFeedbackCells) {
if (i::FLAG_always_opt) return;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Value> fun1, fun2;
{
TEST(IncrementalMarkingPreservesMonomorhpicIC) {
if (i::FLAG_always_opt) return;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
// Prepare function f that contains a monomorphic IC for object
// originating from the same native context.
TEST(IncrementalMarkingClearsMonomorhpicIC) {
if (i::FLAG_always_opt) return;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Value> obj1;
{
TEST(IncrementalMarkingClearsPolymorhpicIC) {
if (i::FLAG_always_opt) return;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Value> obj1, obj2;
{
// after the first time the accessor is fired. We use external string
// to check whether the data is being released since the external string
// resource's callback is fired when the external string is GC'ed.
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
SourceResource* resource = new SourceResource(i::StrDup(source));
{
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::String> source_string = v8::String::NewExternal(resource);
v8::Script::Compile(source_string)->Run();
CHECK(!resource->IsDisposed());
TEST(Regression144230) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
HandleScope scope(isolate);
TEST(Regress159140) {
i::FLAG_allow_natives_syntax = true;
i::FLAG_flush_code_incrementally = true;
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
HandleScope scope(isolate);
TEST(Regress165495) {
i::FLAG_allow_natives_syntax = true;
i::FLAG_flush_code_incrementally = true;
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
HandleScope scope(isolate);
i::FLAG_stress_compaction = false;
i::FLAG_allow_natives_syntax = true;
i::FLAG_flush_code_incrementally = true;
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
HandleScope scope(isolate);
TEST(Regress169928) {
i::FLAG_allow_natives_syntax = true;
i::FLAG_crankshaft = false;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
// Some flags turn Scavenge collections into Mark-sweep collections
// and hence are incompatible with this test case.
i::FLAG_cache_optimized_code = false;
i::FLAG_allow_natives_syntax = true;
i::FLAG_flush_code_incrementally = true;
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
HandleScope scope(isolate);
i::FLAG_cache_optimized_code = false;
i::FLAG_allow_natives_syntax = true;
i::FLAG_flush_code_incrementally = true;
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
HandleScope scope(isolate);
TEST(DeferredHandles) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
v8::HandleScope scope;
using v8::internal::TickSample;
-static v8::Persistent<v8::Context> env;
-
-
static struct {
TickSample* sample;
} trace_env = { NULL };
v8::DeclareExtension kTraceExtensionDeclaration(&kTraceExtension);
-static void InitializeVM() {
- if (env.IsEmpty()) {
- const char* extensions[] = { "v8/trace" };
- v8::ExtensionConfiguration config(1, extensions);
- env = v8::Context::New(&config);
- }
- env->Enter();
-}
-
-
static bool IsAddressWithinFuncCode(JSFunction* function, Address addr) {
i::Code* code = function->code();
return code->contains(addr);
}
static bool IsAddressWithinFuncCode(const char* func_name, Address addr) {
- v8::Local<v8::Value> func = env->Global()->Get(v8_str(func_name));
+ v8::Local<v8::Value> func = CcTest::env()->Global()->Get(v8_str(func_name));
CHECK(func->IsFunction());
JSFunction* js_func = JSFunction::cast(*v8::Utils::OpenHandle(*func));
return IsAddressWithinFuncCode(js_func, addr);
v8::FunctionTemplate::New(construct_call);
constructor_template->SetClassName(v8_str("FPGrabber"));
Local<Function> fun = constructor_template->GetFunction();
- env->Global()->Set(v8_str(constructor_name), fun);
+ CcTest::env()->Global()->Set(v8_str(constructor_name), fun);
}
TickSample sample;
InitTraceEnv(&sample);
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM(TRACE_EXTENSION);
+ v8::HandleScope scope(CcTest::isolate());
// Create global function JSFuncDoTrace which calls
// extension function trace() with the current frame pointer value.
CreateTraceCallerFunction("JSFuncDoTrace", "trace");
TickSample sample;
InitTraceEnv(&sample);
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM(TRACE_EXTENSION);
+ v8::HandleScope scope(CcTest::isolate());
// Create global function JSFuncDoTrace which calls
// extension function js_trace() with the current frame pointer value.
CreateTraceCallerFunction("JSFuncDoTrace", "js_trace");
TEST(PureCStackTrace) {
TickSample sample;
InitTraceEnv(&sample);
- InitializeVM();
+ CcTest::InitializeVM(TRACE_EXTENSION);
// Check that sampler doesn't crash
CHECK_EQ(10, CFunc(10));
}
TEST(JsEntrySp) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM(TRACE_EXTENSION);
+ v8::HandleScope scope(CcTest::isolate());
CHECK_EQ(0, GetJsEntrySp());
CompileRun("a = 1; b = a + 1;");
CHECK_EQ(0, GetJsEntrySp());
using namespace v8::internal;
-static v8::Persistent<v8::Context> env;
-
-static void InitializeVM() {
- if (env.IsEmpty()) env = v8::Context::New();
- env->Enter();
-}
-
TEST(MarkingDeque) {
- InitializeVM();
+ CcTest::InitializeVM();
int mem_size = 20 * kPointerSize;
byte* mem = NewArray<byte>(20*kPointerSize);
Address low = reinterpret_cast<Address>(mem);
FLAG_always_compact = true;
HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB);
- InitializeVM();
+ CcTest::InitializeVM();
- v8::HandleScope sc(env->GetIsolate());
+ v8::HandleScope sc(CcTest::isolate());
// Allocate a fixed array in the new space.
int array_size =
// Test the situation that some objects in new space are promoted to
// the old space
- InitializeVM();
+ CcTest::InitializeVM();
- v8::HandleScope sc(env->GetIsolate());
+ v8::HandleScope sc(CcTest::isolate());
// Do a mark compact GC to shrink the heap.
HEAP->CollectGarbage(OLD_POINTER_SPACE);
TEST(MarkCompactCollector) {
- InitializeVM();
+ CcTest::InitializeVM();
- v8::HandleScope sc(env->GetIsolate());
+ v8::HandleScope sc(CcTest::isolate());
// call mark-compact when heap is empty
HEAP->CollectGarbage(OLD_POINTER_SPACE);
TEST(MapCompact) {
FLAG_max_map_space_pages = 16;
- InitializeVM();
+ CcTest::InitializeVM();
{
v8::HandleScope sc;
TEST(GCCallback) {
- InitializeVM();
+ CcTest::InitializeVM();
HEAP->SetGlobalGCPrologueCallback(&GCPrologueCallbackFunc);
HEAP->SetGlobalGCEpilogueCallback(&GCEpilogueCallbackFunc);
TEST(ObjectGroups) {
FLAG_incremental_marking = false;
- InitializeVM();
+ CcTest::InitializeVM();
GlobalHandles* global_handles = Isolate::Current()->global_handles();
NumberOfWeakCalls = 0;
- v8::HandleScope handle_scope(env->GetIsolate());
+ v8::HandleScope handle_scope(CcTest::isolate());
Handle<Object> g1s1 =
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
TEST(EmptyObjectGroups) {
- InitializeVM();
+ CcTest::InitializeVM();
GlobalHandles* global_handles = Isolate::Current()->global_handles();
- v8::HandleScope handle_scope(env->GetIsolate());
+ v8::HandleScope handle_scope(CcTest::isolate());
Handle<Object> object =
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
// Only Linux has the proc filesystem and only if it is mapped. If it's not
// there we just skip the test.
if (initial_memory >= 0) {
- InitializeVM();
+ CcTest::InitializeVM();
intptr_t delta = MemoryInUse() - initial_memory;
printf("delta: %" V8_PTR_PREFIX "d kB\n", delta / 1024);
if (sizeof(initial_memory) == 8) { // 64-bit.
using namespace v8::internal;
-static v8::Persistent<v8::Context> env;
-
-
-static void InitializeVM() {
- if (env.IsEmpty()) {
- const char* extensions[] = { "v8/print" };
- v8::ExtensionConfiguration config(1, extensions);
- env = v8::Context::New(&config);
- }
- env->Enter();
-}
-
static const int DEEP_DEPTH = 8 * 1024;
static const int SUPER_DEEP_DEPTH = 80 * 1024;
TEST(Traverse) {
printf("TestTraverse\n");
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
ZoneScope zone(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT);
ConsStringGenerationData data(false);
Handle<String> flat = ConstructBalanced(&data);
template<typename BuildString>
void TestStringCharacterStream(BuildString build, int test_cases) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope outer_scope(isolate);
ZoneScope zone(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT);
TEST(DeepAscii) {
printf("TestDeepAscii\n");
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
char* foo = NewArray<char>(DEEP_ASCII_DEPTH);
for (int i = 0; i < DEEP_ASCII_DEPTH; i++) {
TEST(Utf8Conversion) {
// Smoke test for converting strings to utf-8.
- InitializeVM();
- v8::HandleScope handle_scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope handle_scope(CcTest::isolate());
// A simple ascii string
const char* ascii_string = "abcdef12345";
int len =
TEST(ExternalShortStringAdd) {
ZoneScope zonescope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT);
- InitializeVM();
- v8::HandleScope handle_scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope handle_scope(CcTest::isolate());
Zone* zone = Isolate::Current()->runtime_zone();
// Make sure we cover all always-flat lengths and at least one above.
}
// Add the arrays with the short external strings in the global object.
- v8::Handle<v8::Object> global = env->Global();
+ v8::Handle<v8::Object> global = CcTest::env()->Global();
global->Set(v8_str("external_ascii"), ascii_external_strings);
global->Set(v8_str("external_non_ascii"), non_ascii_external_strings);
global->Set(v8_str("max_length"), v8::Integer::New(kMaxLength));
Isolate* isolate = Isolate::Current();
ZoneScope zone(isolate->runtime_zone(), DELETE_ON_EXIT);
- InitializeVM();
- v8::HandleScope handle_scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope handle_scope(CcTest::isolate());
// Lines must be executed sequentially. Combining them into one script
// makes the bug go away.
const char* lines[] = {
TEST(SliceFromCons) {
FLAG_string_slices = true;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
Handle<String> string =
FACTORY->NewStringFromAscii(CStrVector("parentparentparent"));
Handle<String> parent = FACTORY->NewConsString(string, string);
TEST(SliceFromExternal) {
FLAG_string_slices = true;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
AsciiVectorResource resource(
i::Vector<const char>("abcdefghijklmnopqrstuvwxyz", 26));
Handle<String> string = FACTORY->NewExternalStringFromAscii(&resource);
// This tests whether a slice that contains the entire parent string
// actually creates a new string (it should not).
FLAG_string_slices = true;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Value> result;
Handle<String> string;
const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';";
// This tests whether a slice that contains the entire parent string
// actually creates a new string (it should not).
FLAG_string_slices = true;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Value> result;
Handle<String> string;
const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';";
// This tests whether the SubStringStub can handle unsafe arguments.
// If not recognized, those unsafe arguments lead to out-of-bounds reads.
FLAG_allow_natives_syntax = true;
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Value> result;
Handle<String> string;
CompileRun("var short = 'abcdef';");
TEST(RegExpOverflow) {
// Result string has the length 2^32, causing a 32-bit integer overflow.
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
LocalContext context;
v8::V8::IgnoreOutOfMemoryException();
v8::Local<v8::Value> result = CompileRun(
TEST(StringReplaceAtomTwoByteResult) {
- InitializeVM();
- v8::HandleScope scope(env->GetIsolate());
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
LocalContext context;
v8::Local<v8::Value> result = CompileRun(
"var subject = 'ascii~only~string~'; "
using namespace v8::internal;
-static v8::Persistent<v8::Context> env;
-
-static void InitializeVM() {
- if (env.IsEmpty()) {
- const char* extensions[] = { "v8/print" };
- v8::ExtensionConfiguration config(1, extensions);
- env = v8::Context::New(&config);
- }
- env->Enter();
-}
-
TEST(Create) {
- InitializeVM();
+ CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
HandleScope scope(isolate);