| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 #include <wchar.h> // wint_t | 29 #include <wchar.h> // wint_t |
| 30 | 30 |
| 31 #include "v8.h" | 31 #include "v8.h" |
| 32 | 32 |
| 33 #include "compiler.h" | 33 #include "compiler.h" |
| 34 #include "disasm.h" |
| 35 #include "disassembler.h" |
| 34 #include "execution.h" | 36 #include "execution.h" |
| 35 #include "factory.h" | 37 #include "factory.h" |
| 36 #include "platform.h" | 38 #include "platform.h" |
| 37 #include "cctest.h" | 39 #include "cctest.h" |
| 38 | 40 |
| 39 using namespace v8::internal; | 41 using namespace v8::internal; |
| 40 | 42 |
| 41 static v8::Persistent<v8::Context> env; | 43 static v8::Persistent<v8::Context> env; |
| 42 | 44 |
| 43 // --- P r i n t E x t e n s i o n --- | 45 // --- P r i n t E x t e n s i o n --- |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 if (i > 0) | 343 if (i > 0) |
| 342 buffer[i - 1] = '\n'; | 344 buffer[i - 1] = '\n'; |
| 343 memcpy(&buffer[i], function_f, sizeof(function_f) - 1); | 345 memcpy(&buffer[i], function_f, sizeof(function_f) - 1); |
| 344 v8::Handle<v8::String> script_body = v8::String::New(buffer.start()); | 346 v8::Handle<v8::String> script_body = v8::String::New(buffer.start()); |
| 345 v8::Script::Compile(script_body, &origin)->Run(); | 347 v8::Script::Compile(script_body, &origin)->Run(); |
| 346 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 348 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
| 347 env->Global()->Get(v8::String::New("f"))); | 349 env->Global()->Get(v8::String::New("f"))); |
| 348 CHECK_EQ(i, f->GetScriptLineNumber()); | 350 CHECK_EQ(i, f->GetScriptLineNumber()); |
| 349 } | 351 } |
| 350 } | 352 } |
| 353 |
| 354 |
| 355 #ifdef ENABLE_DISASSEMBLER |
| 356 static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj, |
| 357 const char* property_name) { |
| 358 v8::Local<v8::Function> fun = |
| 359 v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name))); |
| 360 return v8::Utils::OpenHandle(*fun); |
| 361 } |
| 362 |
| 363 |
| 364 static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) { |
| 365 // Create a disassembler with default name lookup. |
| 366 disasm::NameConverter name_converter; |
| 367 disasm::Disassembler d(name_converter); |
| 368 |
| 369 if (f->code()->kind() == Code::FUNCTION) { |
| 370 Address pc = f->code()->instruction_start(); |
| 371 int decode_size = |
| 372 Min(f->code()->instruction_size(), |
| 373 static_cast<int>(f->code()->stack_check_table_offset())); |
| 374 Address end = pc + decode_size; |
| 375 |
| 376 v8::internal::EmbeddedVector<char, 128> decode_buffer; |
| 377 while (pc < end) { |
| 378 pc += d.InstructionDecode(decode_buffer, pc); |
| 379 CHECK(strstr(decode_buffer.start(), "mov eax,0x178c29c") == NULL); |
| 380 CHECK(strstr(decode_buffer.start(), "push 0x178c29c") == NULL); |
| 381 CHECK(strstr(decode_buffer.start(), "0x178c29c") == NULL); |
| 382 } |
| 383 } |
| 384 } |
| 385 |
| 386 |
| 387 TEST(SplitConstantsInFullCompiler) { |
| 388 v8::HandleScope scope; |
| 389 LocalContext env; |
| 390 |
| 391 CompileRun("function f() { a = 12345678 }; f();"); |
| 392 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); |
| 393 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
| 394 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); |
| 395 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
| 396 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); |
| 397 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
| 398 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); |
| 399 } |
| 400 #endif |
| OLD | NEW |