Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: test/cctest/test-api.cc

Issue 10837358: Throw a more descriptive exception when blocking 'eval' via CSP. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add SetErrorMessageForCodeGenerationFromStrings API function. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16436 matching lines...) Expand 10 before | Expand all | Expand 10 after
16447 CHECK(!context->IsCodeGenerationFromStringsAllowed()); 16447 CHECK(!context->IsCodeGenerationFromStringsAllowed());
16448 CheckCodeGenerationAllowed(); 16448 CheckCodeGenerationAllowed();
16449 16449
16450 // Set a callback that disallows the code generation. 16450 // Set a callback that disallows the code generation.
16451 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); 16451 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed);
16452 CHECK(!context->IsCodeGenerationFromStringsAllowed()); 16452 CHECK(!context->IsCodeGenerationFromStringsAllowed());
16453 CheckCodeGenerationDisallowed(); 16453 CheckCodeGenerationDisallowed();
16454 } 16454 }
16455 16455
16456 16456
16457 TEST(SetErrorMessageForCodeGenFromStrings) {
16458 v8::HandleScope scope;
16459 LocalContext context;
16460 TryCatch try_catch;
16461
16462 Handle<String> message = v8_str("Message") ;
16463 Handle<String> expected_message = v8_str("Uncaught EvalError: Message");
16464 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed);
16465 context->AllowCodeGenerationFromStrings(false);
16466 context->SetErrorMessageForCodeGenerationFromStrings(message);
16467 Handle<Value> result = CompileRun("eval('42')");
16468 CHECK(result.IsEmpty());
16469 CHECK(try_catch.HasCaught());
16470 Handle<String> actual_message = try_catch.Message()->Get();
16471 CHECK(expected_message->Equals(actual_message));
16472 }
16473
16474
16457 static v8::Handle<Value> NonObjectThis(const v8::Arguments& args) { 16475 static v8::Handle<Value> NonObjectThis(const v8::Arguments& args) {
16458 return v8::Undefined(); 16476 return v8::Undefined();
16459 } 16477 }
16460 16478
16461 16479
16462 THREADED_TEST(CallAPIFunctionOnNonObject) { 16480 THREADED_TEST(CallAPIFunctionOnNonObject) {
16463 v8::HandleScope scope; 16481 v8::HandleScope scope;
16464 LocalContext context; 16482 LocalContext context;
16465 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); 16483 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis);
16466 Handle<Function> function = templ->GetFunction(); 16484 Handle<Function> function = templ->GetFunction();
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after
17437 17455
17438 i::Semaphore* sem_; 17456 i::Semaphore* sem_;
17439 volatile int sem_value_; 17457 volatile int sem_value_;
17440 }; 17458 };
17441 17459
17442 17460
17443 THREADED_TEST(SemaphoreInterruption) { 17461 THREADED_TEST(SemaphoreInterruption) {
17444 ThreadInterruptTest().RunTest(); 17462 ThreadInterruptTest().RunTest();
17445 } 17463 }
17446 #endif // WIN32 17464 #endif // WIN32
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698