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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 v8::HandleScope scope(CcTest::isolate()); | 559 v8::HandleScope scope(CcTest::isolate()); |
560 LocalContext env; | 560 LocalContext env; |
561 v8::ScriptCompiler::Source script_source(v8_str("result = 1")); | 561 v8::ScriptCompiler::Source script_source(v8_str("result = 1")); |
562 v8::Local<v8::String> arg = v8_str("b }"); | 562 v8::Local<v8::String> arg = v8_str("b }"); |
563 v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext( | 563 v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext( |
564 CcTest::isolate(), &script_source, env.local(), 1, &arg, 0, NULL); | 564 CcTest::isolate(), &script_source, env.local(), 1, &arg, 0, NULL); |
565 CHECK(fun.IsEmpty()); | 565 CHECK(fun.IsEmpty()); |
566 } | 566 } |
567 | 567 |
568 | 568 |
| 569 TEST(CompileFunctionInContextScriptOrigin) { |
| 570 CcTest::InitializeVM(); |
| 571 v8::HandleScope scope(CcTest::isolate()); |
| 572 LocalContext env; |
| 573 v8::ScriptOrigin origin(v8_str("test"), |
| 574 v8::Integer::New(CcTest::isolate(), 22), |
| 575 v8::Integer::New(CcTest::isolate(), 41)); |
| 576 v8::ScriptCompiler::Source script_source(v8_str("throw new Error()"), origin); |
| 577 v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext( |
| 578 CcTest::isolate(), &script_source, env.local(), 0, NULL, 0, NULL); |
| 579 CHECK(!fun.IsEmpty()); |
| 580 v8::TryCatch try_catch; |
| 581 CcTest::isolate()->SetCaptureStackTraceForUncaughtExceptions(true); |
| 582 fun->Call(env->Global(), 0, NULL); |
| 583 CHECK(try_catch.HasCaught()); |
| 584 CHECK(!try_catch.Exception().IsEmpty()); |
| 585 v8::Local<v8::StackTrace> stack = |
| 586 v8::Exception::GetStackTrace(try_catch.Exception()); |
| 587 CHECK(!stack.IsEmpty()); |
| 588 CHECK(stack->GetFrameCount() > 0); |
| 589 v8::Local<v8::StackFrame> frame = stack->GetFrame(0); |
| 590 CHECK_EQ(23, frame->GetLineNumber()); |
| 591 CHECK_EQ(42 + strlen("throw "), static_cast<unsigned>(frame->GetColumn())); |
| 592 } |
| 593 |
| 594 |
569 #ifdef ENABLE_DISASSEMBLER | 595 #ifdef ENABLE_DISASSEMBLER |
570 static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj, | 596 static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj, |
571 const char* property_name) { | 597 const char* property_name) { |
572 v8::Local<v8::Function> fun = | 598 v8::Local<v8::Function> fun = |
573 v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name))); | 599 v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name))); |
574 return v8::Utils::OpenHandle(*fun); | 600 return v8::Utils::OpenHandle(*fun); |
575 } | 601 } |
576 | 602 |
577 | 603 |
578 static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) { | 604 static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 CompileRun("function f() { a = 12345678 }; f();"); | 640 CompileRun("function f() { a = 12345678 }; f();"); |
615 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 641 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
616 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 642 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
617 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 643 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
618 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 644 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
619 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 645 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
620 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 646 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
621 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 647 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
622 } | 648 } |
623 #endif | 649 #endif |
OLD | NEW |