| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 v8::HandleScope scope(CcTest::isolate()); | 507 v8::HandleScope scope(CcTest::isolate()); |
| 508 LocalContext env; | 508 LocalContext env; |
| 509 v8::ScriptCompiler::Source script_source(v8_str("result = 1")); | 509 v8::ScriptCompiler::Source script_source(v8_str("result = 1")); |
| 510 v8::Local<v8::String> arg = v8_str("b }"); | 510 v8::Local<v8::String> arg = v8_str("b }"); |
| 511 v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext( | 511 v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext( |
| 512 CcTest::isolate(), &script_source, env.local(), 1, &arg, 0, NULL); | 512 CcTest::isolate(), &script_source, env.local(), 1, &arg, 0, NULL); |
| 513 CHECK(fun.IsEmpty()); | 513 CHECK(fun.IsEmpty()); |
| 514 } | 514 } |
| 515 | 515 |
| 516 | 516 |
| 517 TEST(CompileFunctionInContextScriptOrigin) { |
| 518 CcTest::InitializeVM(); |
| 519 v8::HandleScope scope(CcTest::isolate()); |
| 520 LocalContext env; |
| 521 v8::ScriptOrigin origin(v8_str("test"), |
| 522 v8::Integer::New(CcTest::isolate(), 22), |
| 523 v8::Integer::New(CcTest::isolate(), 41)); |
| 524 v8::ScriptCompiler::Source script_source(v8_str("throw new Error()"), origin); |
| 525 v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext( |
| 526 CcTest::isolate(), &script_source, env.local(), 0, NULL, 0, NULL); |
| 527 CHECK(!fun.IsEmpty()); |
| 528 v8::TryCatch try_catch; |
| 529 CcTest::isolate()->SetCaptureStackTraceForUncaughtExceptions(true); |
| 530 fun->Call(env->Global(), 0, NULL); |
| 531 CHECK(try_catch.HasCaught()); |
| 532 CHECK(!try_catch.Exception().IsEmpty()); |
| 533 v8::Local<v8::StackTrace> stack = |
| 534 v8::Exception::GetStackTrace(try_catch.Exception()); |
| 535 CHECK(!stack.IsEmpty()); |
| 536 CHECK(stack->GetFrameCount() > 0); |
| 537 v8::Local<v8::StackFrame> frame = stack->GetFrame(0); |
| 538 CHECK_EQ(23, frame->GetLineNumber()); |
| 539 CHECK_EQ(42 + strlen("throw "), static_cast<unsigned>(frame->GetColumn())); |
| 540 } |
| 541 |
| 542 |
| 517 #ifdef ENABLE_DISASSEMBLER | 543 #ifdef ENABLE_DISASSEMBLER |
| 518 static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj, | 544 static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj, |
| 519 const char* property_name) { | 545 const char* property_name) { |
| 520 v8::Local<v8::Function> fun = | 546 v8::Local<v8::Function> fun = |
| 521 v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name))); | 547 v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name))); |
| 522 return v8::Utils::OpenHandle(*fun); | 548 return v8::Utils::OpenHandle(*fun); |
| 523 } | 549 } |
| 524 | 550 |
| 525 | 551 |
| 526 static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) { | 552 static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 CompileRun("function f() { a = 12345678 }; f();"); | 585 CompileRun("function f() { a = 12345678 }; f();"); |
| 560 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 586 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 561 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 587 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
| 562 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 588 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 563 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 589 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
| 564 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 590 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 565 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 591 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
| 566 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 592 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 567 } | 593 } |
| 568 #endif | 594 #endif |
| OLD | NEW |