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

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

Issue 3165016: Allow allocation in FailedAccessCheckCallback to allow embedders to... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 4 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/top.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 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 CHECK(result->IsBoolean()); 76 CHECK(result->IsBoolean());
77 CHECK_EQ(expected, result->BooleanValue()); 77 CHECK_EQ(expected, result->BooleanValue());
78 } 78 }
79 79
80 80
81 static void ExpectTrue(const char* code) { 81 static void ExpectTrue(const char* code) {
82 ExpectBoolean(code, true); 82 ExpectBoolean(code, true);
83 } 83 }
84 84
85 85
86 static void ExpectFalse(const char* code) {
87 ExpectBoolean(code, false);
88 }
89
90
86 static void ExpectObject(const char* code, Local<Value> expected) { 91 static void ExpectObject(const char* code, Local<Value> expected) {
87 Local<Value> result = CompileRun(code); 92 Local<Value> result = CompileRun(code);
88 CHECK(result->Equals(expected)); 93 CHECK(result->Equals(expected));
89 } 94 }
90 95
91 96
97 static void ExpectUndefined(const char* code) {
98 Local<Value> result = CompileRun(code);
99 CHECK(result->IsUndefined());
100 }
101
102
92 static int signature_callback_count; 103 static int signature_callback_count;
93 static v8::Handle<Value> IncrementingSignatureCallback( 104 static v8::Handle<Value> IncrementingSignatureCallback(
94 const v8::Arguments& args) { 105 const v8::Arguments& args) {
95 ApiTestFuzzer::Fuzz(); 106 ApiTestFuzzer::Fuzz();
96 signature_callback_count++; 107 signature_callback_count++;
97 v8::Handle<v8::Array> result = v8::Array::New(args.Length()); 108 v8::Handle<v8::Array> result = v8::Array::New(args.Length());
98 for (int i = 0; i < args.Length(); i++) 109 for (int i = 0; i < args.Length(); i++)
99 result->Set(v8::Integer::New(i), args[i]); 110 result->Set(v8::Integer::New(i), args[i]);
100 return result; 111 return result;
101 } 112 }
(...skipping 11080 matching lines...) Expand 10 before | Expand all | Expand 10 after
11182 11193
11183 ExpectString("str2.substring(2, 10);", "elspenda"); 11194 ExpectString("str2.substring(2, 10);", "elspenda");
11184 11195
11185 ExpectString("str2.substring(2, 20);", "elspendabelabelspe"); 11196 ExpectString("str2.substring(2, 20);", "elspendabelabelspe");
11186 11197
11187 ExpectString("str2.charAt(2);", "e"); 11198 ExpectString("str2.charAt(2);", "e");
11188 11199
11189 reresult = CompileRun("str2.charCodeAt(2);"); 11200 reresult = CompileRun("str2.charCodeAt(2);");
11190 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value()); 11201 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value());
11191 } 11202 }
11203
11204
11205 // Failed access check callback that performs a GC on each invocation.
11206 void FailedAccessCheckCallbackGC(Local<v8::Object> target,
11207 v8::AccessType type,
11208 Local<v8::Value> data) {
11209 i::Heap::CollectAllGarbage(true);
11210 }
11211
11212
11213 TEST(GCInFailedAccessCheckCallback) {
11214 // Install a failed access check callback that performs a GC on each
11215 // invocation. Then force the callback to be called from va
11216
11217 v8::V8::Initialize();
11218 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC);
11219
11220 v8::HandleScope scope;
11221
11222 // Create an ObjectTemplate for global objects and install access
11223 // check callbacks that will block access.
11224 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
11225 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker,
11226 IndexedGetAccessBlocker,
11227 v8::Handle<v8::Value>(),
11228 false);
11229
11230 // Create a context and set an x property on it's global object.
11231 LocalContext context0(NULL, global_template);
11232 context0->Global()->Set(v8_str("x"), v8_num(42));
11233 v8::Handle<v8::Object> global0 = context0->Global();
11234
11235 // Create a context with a different security token so that the
11236 // failed access check callback will be called on each access.
11237 LocalContext context1(NULL, global_template);
11238 context1->Global()->Set(v8_str("other"), global0);
11239
11240 // Get property with failed access check.
11241 ExpectUndefined("other.x");
11242
11243 // Get element with failed access check.
11244 ExpectUndefined("other[0]");
11245
11246 // Set property with failed access check.
11247 v8::Handle<v8::Value> result = CompileRun("other.x = new Object()");
11248 CHECK(result->IsObject());
11249
11250 // Set element with failed access check.
11251 result = CompileRun("other[0] = new Object()");
11252 CHECK(result->IsObject());
11253
11254 // Get property attribute with failed access check.
11255 ExpectFalse("\'x\' in other");
11256
11257 // Get property attribute for element with failed access check.
11258 ExpectFalse("0 in other");
11259
11260 // Delete property.
11261 ExpectFalse("delete other.x");
11262
11263 // Delete element.
11264 CHECK_EQ(false, global0->Delete(0));
11265
11266 // DefineAccessor.
11267 CHECK_EQ(false,
11268 global0->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("x")));
11269
11270 // Define JavaScript accessor.
11271 ExpectUndefined("Object.prototype.__defineGetter__.call("
11272 " other, \'x\', function() { return 42; })");
11273
11274 // LookupAccessor.
11275 ExpectUndefined("Object.prototype.__lookupGetter__.call("
11276 " other, \'x\')");
11277
11278 // HasLocalElement.
11279 ExpectFalse("Object.prototype.hasOwnProperty.call(other, \'0\')");
11280
11281 CHECK_EQ(false, global0->HasRealIndexedProperty(0));
11282 CHECK_EQ(false, global0->HasRealNamedProperty(v8_str("x")));
11283 CHECK_EQ(false, global0->HasRealNamedCallbackProperty(v8_str("x")));
11284
11285 // Reset the failed access check callback so it does not influence
11286 // the other tests.
11287 v8::V8::SetFailedAccessCheckCallbackFunction(NULL);
11288 }
OLDNEW
« no previous file with comments | « src/top.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698