diff options
Diffstat (limited to 'deps/v8/test/cctest/test-compiler.cc')
-rw-r--r-- | deps/v8/test/cctest/test-compiler.cc | 96 |
1 files changed, 73 insertions, 23 deletions
diff --git a/deps/v8/test/cctest/test-compiler.cc b/deps/v8/test/cctest/test-compiler.cc index 9f21b78dd6..4c5f197bc6 100644 --- a/deps/v8/test/cctest/test-compiler.cc +++ b/deps/v8/test/cctest/test-compiler.cc @@ -31,10 +31,11 @@ #include "v8.h" #include "compiler.h" +#include "disasm.h" +#include "disassembler.h" #include "execution.h" #include "factory.h" #include "platform.h" -#include "top.h" #include "cctest.h" using namespace v8::internal; @@ -99,21 +100,21 @@ static void InitializeVM() { static MaybeObject* GetGlobalProperty(const char* name) { - Handle<String> symbol = Factory::LookupAsciiSymbol(name); - return Top::context()->global()->GetProperty(*symbol); + Handle<String> symbol = FACTORY->LookupAsciiSymbol(name); + return Isolate::Current()->context()->global()->GetProperty(*symbol); } static void SetGlobalProperty(const char* name, Object* value) { Handle<Object> object(value); - Handle<String> symbol = Factory::LookupAsciiSymbol(name); - Handle<JSObject> global(Top::context()->global()); + Handle<String> symbol = FACTORY->LookupAsciiSymbol(name); + Handle<JSObject> global(Isolate::Current()->context()->global()); SetProperty(global, symbol, object, NONE, kNonStrictMode); } static Handle<JSFunction> Compile(const char* source) { - Handle<String> source_code(Factory::NewStringFromUtf8(CStrVector(source))); + Handle<String> source_code(FACTORY->NewStringFromUtf8(CStrVector(source))); Handle<SharedFunctionInfo> shared_function = Compiler::Compile(source_code, Handle<String>(), @@ -123,8 +124,8 @@ static Handle<JSFunction> Compile(const char* source) { NULL, Handle<String>::null(), NOT_NATIVES_CODE); - return Factory::NewFunctionFromSharedFunctionInfo(shared_function, - Top::global_context()); + return FACTORY->NewFunctionFromSharedFunctionInfo(shared_function, + Isolate::Current()->global_context()); } @@ -137,7 +138,7 @@ static double Inc(int x) { if (fun.is_null()) return -1; bool has_pending_exception; - Handle<JSObject> global(Top::context()->global()); + Handle<JSObject> global(Isolate::Current()->context()->global()); Execution::Call(fun, global, 0, NULL, &has_pending_exception); CHECK(!has_pending_exception); return GetGlobalProperty("result")->ToObjectChecked()->Number(); @@ -158,7 +159,7 @@ static double Add(int x, int y) { SetGlobalProperty("x", Smi::FromInt(x)); SetGlobalProperty("y", Smi::FromInt(y)); bool has_pending_exception; - Handle<JSObject> global(Top::context()->global()); + Handle<JSObject> global(Isolate::Current()->context()->global()); Execution::Call(fun, global, 0, NULL, &has_pending_exception); CHECK(!has_pending_exception); return GetGlobalProperty("result")->ToObjectChecked()->Number(); @@ -178,7 +179,7 @@ static double Abs(int x) { SetGlobalProperty("x", Smi::FromInt(x)); bool has_pending_exception; - Handle<JSObject> global(Top::context()->global()); + Handle<JSObject> global(Isolate::Current()->context()->global()); Execution::Call(fun, global, 0, NULL, &has_pending_exception); CHECK(!has_pending_exception); return GetGlobalProperty("result")->ToObjectChecked()->Number(); @@ -199,7 +200,7 @@ static double Sum(int n) { SetGlobalProperty("n", Smi::FromInt(n)); bool has_pending_exception; - Handle<JSObject> global(Top::context()->global()); + Handle<JSObject> global(Isolate::Current()->context()->global()); Execution::Call(fun, global, 0, NULL, &has_pending_exception); CHECK(!has_pending_exception); return GetGlobalProperty("result")->ToObjectChecked()->Number(); @@ -220,7 +221,7 @@ TEST(Print) { Handle<JSFunction> fun = Compile(source); if (fun.is_null()) return; bool has_pending_exception; - Handle<JSObject> global(Top::context()->global()); + Handle<JSObject> global(Isolate::Current()->context()->global()); Execution::Call(fun, global, 0, NULL, &has_pending_exception); CHECK(!has_pending_exception); } @@ -253,7 +254,7 @@ TEST(Stuff) { Handle<JSFunction> fun = Compile(source); CHECK(!fun.is_null()); bool has_pending_exception; - Handle<JSObject> global(Top::context()->global()); + Handle<JSObject> global(Isolate::Current()->context()->global()); Execution::Call(fun, global, 0, NULL, &has_pending_exception); CHECK(!has_pending_exception); CHECK_EQ(511.0, GetGlobalProperty("r")->ToObjectChecked()->Number()); @@ -268,11 +269,12 @@ TEST(UncaughtThrow) { Handle<JSFunction> fun = Compile(source); CHECK(!fun.is_null()); bool has_pending_exception; - Handle<JSObject> global(Top::context()->global()); + Handle<JSObject> global(Isolate::Current()->context()->global()); Handle<Object> result = Execution::Call(fun, global, 0, NULL, &has_pending_exception); CHECK(has_pending_exception); - CHECK_EQ(42.0, Top::pending_exception()->ToObjectChecked()->Number()); + CHECK_EQ(42.0, Isolate::Current()->pending_exception()-> + ToObjectChecked()->Number()); } @@ -293,18 +295,18 @@ TEST(C2JSFrames) { // Run the generated code to populate the global object with 'foo'. bool has_pending_exception; - Handle<JSObject> global(Top::context()->global()); + Handle<JSObject> global(Isolate::Current()->context()->global()); Execution::Call(fun0, global, 0, NULL, &has_pending_exception); CHECK(!has_pending_exception); - Object* foo_symbol = Factory::LookupAsciiSymbol("foo")->ToObjectChecked(); - MaybeObject* fun1_object = - Top::context()->global()->GetProperty(String::cast(foo_symbol)); + Object* foo_symbol = FACTORY->LookupAsciiSymbol("foo")->ToObjectChecked(); + MaybeObject* fun1_object = Isolate::Current()->context()->global()-> + GetProperty(String::cast(foo_symbol)); Handle<Object> fun1(fun1_object->ToObjectChecked()); CHECK(fun1->IsJSFunction()); Object** argv[1] = { - Handle<Object>::cast(Factory::LookupAsciiSymbol("hello")).location() + Handle<Object>::cast(FACTORY->LookupAsciiSymbol("hello")).location() }; Execution::Call(Handle<JSFunction>::cast(fun1), global, 1, argv, &has_pending_exception); @@ -318,8 +320,8 @@ TEST(Regression236) { InitializeVM(); v8::HandleScope scope; - Handle<Script> script = Factory::NewScript(Factory::empty_string()); - script->set_source(Heap::undefined_value()); + Handle<Script> script = FACTORY->NewScript(FACTORY->empty_string()); + script->set_source(HEAP->undefined_value()); CHECK_EQ(-1, GetScriptLineNumber(script, 0)); CHECK_EQ(-1, GetScriptLineNumber(script, 100)); CHECK_EQ(-1, GetScriptLineNumber(script, -1)); @@ -348,3 +350,51 @@ TEST(GetScriptLineNumber) { CHECK_EQ(i, f->GetScriptLineNumber()); } } + + +#ifdef ENABLE_DISASSEMBLER +static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj, + const char* property_name) { + v8::Local<v8::Function> fun = + v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name))); + return v8::Utils::OpenHandle(*fun); +} + + +static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) { + // Create a disassembler with default name lookup. + disasm::NameConverter name_converter; + disasm::Disassembler d(name_converter); + + if (f->code()->kind() == Code::FUNCTION) { + Address pc = f->code()->instruction_start(); + int decode_size = + Min(f->code()->instruction_size(), + static_cast<int>(f->code()->stack_check_table_offset())); + Address end = pc + decode_size; + + v8::internal::EmbeddedVector<char, 128> decode_buffer; + while (pc < end) { + pc += d.InstructionDecode(decode_buffer, pc); + CHECK(strstr(decode_buffer.start(), "mov eax,0x178c29c") == NULL); + CHECK(strstr(decode_buffer.start(), "push 0x178c29c") == NULL); + CHECK(strstr(decode_buffer.start(), "0x178c29c") == NULL); + } + } +} + + +TEST(SplitConstantsInFullCompiler) { + v8::HandleScope scope; + LocalContext env; + + CompileRun("function f() { a = 12345678 }; f();"); + CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); + CompileRun("function f(x) { a = 12345678 + x}; f(1);"); + CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); + CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); + CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); + CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); + CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); +} +#endif |