OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 14413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14424 CHECK(instance->HasOwnProperty(v8_str("bar"))); | 14424 CHECK(instance->HasOwnProperty(v8_str("bar"))); |
14425 } | 14425 } |
14426 } | 14426 } |
14427 | 14427 |
14428 | 14428 |
14429 void CheckCodeGenerationAllowed() { | 14429 void CheckCodeGenerationAllowed() { |
14430 Handle<Value> result = CompileRun("eval('42')"); | 14430 Handle<Value> result = CompileRun("eval('42')"); |
14431 CHECK_EQ(42, result->Int32Value()); | 14431 CHECK_EQ(42, result->Int32Value()); |
14432 result = CompileRun("(function(e) { return e('42'); })(eval)"); | 14432 result = CompileRun("(function(e) { return e('42'); })(eval)"); |
14433 CHECK_EQ(42, result->Int32Value()); | 14433 CHECK_EQ(42, result->Int32Value()); |
14434 result = CompileRun("execScript('42')"); | |
14435 CHECK(!result.IsEmpty()); | |
14436 result = CompileRun("var f = new Function('return 42'); f()"); | 14434 result = CompileRun("var f = new Function('return 42'); f()"); |
14437 CHECK_EQ(42, result->Int32Value()); | 14435 CHECK_EQ(42, result->Int32Value()); |
14438 } | 14436 } |
14439 | 14437 |
14440 | 14438 |
14441 void CheckCodeGenerationDisallowed() { | 14439 void CheckCodeGenerationDisallowed() { |
14442 TryCatch try_catch; | 14440 TryCatch try_catch; |
14443 | 14441 |
14444 Handle<Value> result = CompileRun("eval('42')"); | 14442 Handle<Value> result = CompileRun("eval('42')"); |
14445 CHECK(result.IsEmpty()); | 14443 CHECK(result.IsEmpty()); |
14446 CHECK(try_catch.HasCaught()); | 14444 CHECK(try_catch.HasCaught()); |
14447 try_catch.Reset(); | 14445 try_catch.Reset(); |
14448 | 14446 |
14449 result = CompileRun("(function(e) { return e('42'); })(eval)"); | 14447 result = CompileRun("(function(e) { return e('42'); })(eval)"); |
14450 CHECK(result.IsEmpty()); | 14448 CHECK(result.IsEmpty()); |
14451 CHECK(try_catch.HasCaught()); | 14449 CHECK(try_catch.HasCaught()); |
14452 try_catch.Reset(); | 14450 try_catch.Reset(); |
14453 | 14451 |
14454 result = CompileRun("execScript('42')"); | |
14455 CHECK(result.IsEmpty()); | |
14456 CHECK(try_catch.HasCaught()); | |
14457 try_catch.Reset(); | |
14458 | |
14459 result = CompileRun("var f = new Function('return 42'); f()"); | 14452 result = CompileRun("var f = new Function('return 42'); f()"); |
14460 CHECK(result.IsEmpty()); | 14453 CHECK(result.IsEmpty()); |
14461 CHECK(try_catch.HasCaught()); | 14454 CHECK(try_catch.HasCaught()); |
14462 } | 14455 } |
14463 | 14456 |
14464 | 14457 |
14465 bool CodeGenerationAllowed(Local<Context> context) { | 14458 bool CodeGenerationAllowed(Local<Context> context) { |
14466 ApiTestFuzzer::Fuzz(); | 14459 ApiTestFuzzer::Fuzz(); |
14467 return true; | 14460 return true; |
14468 } | 14461 } |
14469 | 14462 |
14470 | 14463 |
14471 bool CodeGenerationDisallowed(Local<Context> context) { | 14464 bool CodeGenerationDisallowed(Local<Context> context) { |
14472 ApiTestFuzzer::Fuzz(); | 14465 ApiTestFuzzer::Fuzz(); |
14473 return false; | 14466 return false; |
14474 } | 14467 } |
14475 | 14468 |
14476 | 14469 |
14477 THREADED_TEST(AllowCodeGenFromStrings) { | 14470 THREADED_TEST(AllowCodeGenFromStrings) { |
14478 v8::HandleScope scope; | 14471 v8::HandleScope scope; |
14479 LocalContext context; | 14472 LocalContext context; |
14480 | 14473 |
14481 // eval, execScript and the Function constructor allowed by default. | 14474 // eval and the Function constructor allowed by default. |
14482 CheckCodeGenerationAllowed(); | 14475 CheckCodeGenerationAllowed(); |
14483 | 14476 |
14484 // Disallow eval, execScript and the Function constructor. | 14477 // Disallow eval and the Function constructor. |
14485 context->AllowCodeGenerationFromStrings(false); | 14478 context->AllowCodeGenerationFromStrings(false); |
14486 CheckCodeGenerationDisallowed(); | 14479 CheckCodeGenerationDisallowed(); |
14487 | 14480 |
14488 // Allow again. | 14481 // Allow again. |
14489 context->AllowCodeGenerationFromStrings(true); | 14482 context->AllowCodeGenerationFromStrings(true); |
14490 CheckCodeGenerationAllowed(); | 14483 CheckCodeGenerationAllowed(); |
14491 | 14484 |
14492 // Disallow but setting a global callback that will allow the calls. | 14485 // Disallow but setting a global callback that will allow the calls. |
14493 context->AllowCodeGenerationFromStrings(false); | 14486 context->AllowCodeGenerationFromStrings(false); |
14494 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationAllowed); | 14487 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationAllowed); |
(...skipping 12 matching lines...) Expand all Loading... |
14507 | 14500 |
14508 THREADED_TEST(CallAPIFunctionOnNonObject) { | 14501 THREADED_TEST(CallAPIFunctionOnNonObject) { |
14509 v8::HandleScope scope; | 14502 v8::HandleScope scope; |
14510 LocalContext context; | 14503 LocalContext context; |
14511 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); | 14504 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); |
14512 Handle<Function> function = templ->GetFunction(); | 14505 Handle<Function> function = templ->GetFunction(); |
14513 context->Global()->Set(v8_str("f"), function); | 14506 context->Global()->Set(v8_str("f"), function); |
14514 TryCatch try_catch; | 14507 TryCatch try_catch; |
14515 CompileRun("f.call(2)"); | 14508 CompileRun("f.call(2)"); |
14516 } | 14509 } |
OLD | NEW |