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

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

Issue 6250133: Merge r6592, r6612, r6618 and r6626 into 2.4 branch (Closed) Base URL: http://v8.googlecode.com/svn/branches/2.4/
Patch Set: '' Created 9 years, 10 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/version.cc ('k') | test/mjsunit/get-own-property-descriptor.js » ('j') | 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 5114 matching lines...) Expand 10 before | Expand all | Expand 10 after
5125 // the global object for env2 which has the same security token as env1. 5125 // the global object for env2 which has the same security token as env1.
5126 result = CompileRun("other.p"); 5126 result = CompileRun("other.p");
5127 CHECK(result->IsInt32()); 5127 CHECK(result->IsInt32());
5128 CHECK_EQ(42, result->Int32Value()); 5128 CHECK_EQ(42, result->Int32Value());
5129 5129
5130 env2.Dispose(); 5130 env2.Dispose();
5131 env3.Dispose(); 5131 env3.Dispose();
5132 } 5132 }
5133 5133
5134 5134
5135 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false };
5135 static bool NamedAccessBlocker(Local<v8::Object> global, 5136 static bool NamedAccessBlocker(Local<v8::Object> global,
5136 Local<Value> name, 5137 Local<Value> name,
5137 v8::AccessType type, 5138 v8::AccessType type,
5138 Local<Value> data) { 5139 Local<Value> data) {
5139 return Context::GetCurrent()->Global()->Equals(global); 5140 return Context::GetCurrent()->Global()->Equals(global) ||
5141 allowed_access_type[type];
5140 } 5142 }
5141 5143
5142 5144
5143 static bool IndexedAccessBlocker(Local<v8::Object> global, 5145 static bool IndexedAccessBlocker(Local<v8::Object> global,
5144 uint32_t key, 5146 uint32_t key,
5145 v8::AccessType type, 5147 v8::AccessType type,
5146 Local<Value> data) { 5148 Local<Value> data) {
5147 return Context::GetCurrent()->Global()->Equals(global); 5149 return Context::GetCurrent()->Global()->Equals(global) ||
5150 allowed_access_type[type];
5148 } 5151 }
5149 5152
5150 5153
5151 static int g_echo_value = -1; 5154 static int g_echo_value = -1;
5152 static v8::Handle<Value> EchoGetter(Local<String> name, 5155 static v8::Handle<Value> EchoGetter(Local<String> name,
5153 const AccessorInfo& info) { 5156 const AccessorInfo& info) {
5154 return v8_num(g_echo_value); 5157 return v8_num(g_echo_value);
5155 } 5158 }
5156 5159
5157 5160
(...skipping 11 matching lines...) Expand all
5169 return v8::Undefined(); 5172 return v8::Undefined();
5170 } 5173 }
5171 5174
5172 5175
5173 static void UnreachableSetter(Local<String>, Local<Value>, 5176 static void UnreachableSetter(Local<String>, Local<Value>,
5174 const AccessorInfo&) { 5177 const AccessorInfo&) {
5175 CHECK(false); // This function should nto be called. 5178 CHECK(false); // This function should nto be called.
5176 } 5179 }
5177 5180
5178 5181
5179 THREADED_TEST(AccessControl) { 5182 TEST(AccessControl) {
5180 v8::HandleScope handle_scope; 5183 v8::HandleScope handle_scope;
5181 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 5184 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
5182 5185
5183 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 5186 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
5184 IndexedAccessBlocker); 5187 IndexedAccessBlocker);
5185 5188
5186 // Add an accessor accessible by cross-domain JS code. 5189 // Add an accessor accessible by cross-domain JS code.
5187 global_template->SetAccessor( 5190 global_template->SetAccessor(
5188 v8_str("accessible_prop"), 5191 v8_str("accessible_prop"),
5189 EchoGetter, EchoSetter, 5192 EchoGetter, EchoSetter,
5190 v8::Handle<Value>(), 5193 v8::Handle<Value>(),
5191 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); 5194 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
5192 5195
5193 // Add an accessor that is not accessible by cross-domain JS code. 5196 // Add an accessor that is not accessible by cross-domain JS code.
5194 global_template->SetAccessor(v8_str("blocked_prop"), 5197 global_template->SetAccessor(v8_str("blocked_prop"),
5195 UnreachableGetter, UnreachableSetter, 5198 UnreachableGetter, UnreachableSetter,
5196 v8::Handle<Value>(), 5199 v8::Handle<Value>(),
5197 v8::DEFAULT); 5200 v8::DEFAULT);
5198 5201
5199 // Create an environment 5202 // Create an environment
5200 v8::Persistent<Context> context0 = Context::New(NULL, global_template); 5203 v8::Persistent<Context> context0 = Context::New(NULL, global_template);
5201 context0->Enter(); 5204 context0->Enter();
5202 5205
5203 v8::Handle<v8::Object> global0 = context0->Global(); 5206 v8::Handle<v8::Object> global0 = context0->Global();
5204 5207
5208 // Define a property with JS getter and setter.
5209 CompileRun(
5210 "function getter() { return 'getter'; };\n"
5211 "function setter() { return 'setter'; }\n"
5212 "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})");
5213
5214 Local<Value> getter = global0->Get(v8_str("getter"));
5215 Local<Value> setter = global0->Get(v8_str("setter"));
5216
5217 // And define normal element.
5218 global0->Set(239, v8_str("239"));
5219
5220 // Define an element with JS getter and setter.
5221 CompileRun(
5222 "function el_getter() { return 'el_getter'; };\n"
5223 "function el_setter() { return 'el_setter'; };\n"
5224 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});");
5225
5226 Local<Value> el_getter = global0->Get(v8_str("el_getter"));
5227 Local<Value> el_setter = global0->Get(v8_str("el_setter"));
5228
5205 v8::HandleScope scope1; 5229 v8::HandleScope scope1;
5206 5230
5207 v8::Persistent<Context> context1 = Context::New(); 5231 v8::Persistent<Context> context1 = Context::New();
5208 context1->Enter(); 5232 context1->Enter();
5209 5233
5210 v8::Handle<v8::Object> global1 = context1->Global(); 5234 v8::Handle<v8::Object> global1 = context1->Global();
5211 global1->Set(v8_str("other"), global0); 5235 global1->Set(v8_str("other"), global0);
5212 5236
5237 // Access blocked property.
5238 CompileRun("other.blocked_prop = 1");
5239
5240 ExpectUndefined("other.blocked_prop");
5241 ExpectUndefined(
5242 "Object.getOwnPropertyDescriptor(other, 'blocked_prop')");
5243 ExpectFalse("propertyIsEnumerable.call(other, 'blocked_prop')");
5244
5245 // Enable ACCESS_HAS
5246 allowed_access_type[v8::ACCESS_HAS] = true;
5247 ExpectUndefined("other.blocked_prop");
5248 // ... and now we can get the descriptor...
5249 ExpectUndefined(
5250 "Object.getOwnPropertyDescriptor(other, 'blocked_prop').value");
5251 // ... and enumerate the property.
5252 ExpectTrue("propertyIsEnumerable.call(other, 'blocked_prop')");
5253 allowed_access_type[v8::ACCESS_HAS] = false;
5254
5255 // Access blocked element.
5256 CompileRun("other[239] = 1");
5257
5258 ExpectUndefined("other[239]");
5259 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '239')");
5260 ExpectFalse("propertyIsEnumerable.call(other, '239')");
5261
5262 // Enable ACCESS_HAS
5263 allowed_access_type[v8::ACCESS_HAS] = true;
5264 ExpectUndefined("other[239]");
5265 // ... and now we can get the descriptor...
5266 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '239').value");
5267 // ... and enumerate the property.
5268 ExpectTrue("propertyIsEnumerable.call(other, '239')");
5269 allowed_access_type[v8::ACCESS_HAS] = false;
5270
5271 // Access a property with JS accessor.
5272 CompileRun("other.js_accessor_p = 2");
5273
5274 ExpectUndefined("other.js_accessor_p");
5275 ExpectUndefined(
5276 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p')");
5277
5278 // Enable ACCESS_HAS.
5279 allowed_access_type[v8::ACCESS_HAS] = true;
5280 ExpectUndefined("other.js_accessor_p");
5281 ExpectUndefined(
5282 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
5283 ExpectUndefined(
5284 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
5285 ExpectUndefined(
5286 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
5287 allowed_access_type[v8::ACCESS_HAS] = false;
5288
5289 // Enable both ACCESS_HAS and ACCESS_GET.
5290 allowed_access_type[v8::ACCESS_HAS] = true;
5291 allowed_access_type[v8::ACCESS_GET] = true;
5292
5293 ExpectString("other.js_accessor_p", "getter");
5294 ExpectObject(
5295 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
5296 ExpectUndefined(
5297 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
5298 ExpectUndefined(
5299 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
5300
5301 allowed_access_type[v8::ACCESS_GET] = false;
5302 allowed_access_type[v8::ACCESS_HAS] = false;
5303
5304 // Enable both ACCESS_HAS and ACCESS_SET.
5305 allowed_access_type[v8::ACCESS_HAS] = true;
5306 allowed_access_type[v8::ACCESS_SET] = true;
5307
5308 ExpectUndefined("other.js_accessor_p");
5309 ExpectUndefined(
5310 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
5311 ExpectObject(
5312 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
5313 ExpectUndefined(
5314 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
5315
5316 allowed_access_type[v8::ACCESS_SET] = false;
5317 allowed_access_type[v8::ACCESS_HAS] = false;
5318
5319 // Enable both ACCESS_HAS, ACCESS_GET and ACCESS_SET.
5320 allowed_access_type[v8::ACCESS_HAS] = true;
5321 allowed_access_type[v8::ACCESS_GET] = true;
5322 allowed_access_type[v8::ACCESS_SET] = true;
5323
5324 ExpectString("other.js_accessor_p", "getter");
5325 ExpectObject(
5326 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
5327 ExpectObject(
5328 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
5329 ExpectUndefined(
5330 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
5331
5332 allowed_access_type[v8::ACCESS_SET] = false;
5333 allowed_access_type[v8::ACCESS_GET] = false;
5334 allowed_access_type[v8::ACCESS_HAS] = false;
5335
5336 // Access an element with JS accessor.
5337 CompileRun("other[42] = 2");
5338
5339 ExpectUndefined("other[42]");
5340 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42')");
5341
5342 // Enable ACCESS_HAS.
5343 allowed_access_type[v8::ACCESS_HAS] = true;
5344 ExpectUndefined("other[42]");
5345 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').get");
5346 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').set");
5347 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value");
5348 allowed_access_type[v8::ACCESS_HAS] = false;
5349
5350 // Enable both ACCESS_HAS and ACCESS_GET.
5351 allowed_access_type[v8::ACCESS_HAS] = true;
5352 allowed_access_type[v8::ACCESS_GET] = true;
5353
5354 ExpectString("other[42]", "el_getter");
5355 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').get", el_getter);
5356 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').set");
5357 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value");
5358
5359 allowed_access_type[v8::ACCESS_GET] = false;
5360 allowed_access_type[v8::ACCESS_HAS] = false;
5361
5362 // Enable both ACCESS_HAS and ACCESS_SET.
5363 allowed_access_type[v8::ACCESS_HAS] = true;
5364 allowed_access_type[v8::ACCESS_SET] = true;
5365
5366 ExpectUndefined("other[42]");
5367 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').get");
5368 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').set", el_setter);
5369 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value");
5370
5371 allowed_access_type[v8::ACCESS_SET] = false;
5372 allowed_access_type[v8::ACCESS_HAS] = false;
5373
5374 // Enable both ACCESS_HAS, ACCESS_GET and ACCESS_SET.
5375 allowed_access_type[v8::ACCESS_HAS] = true;
5376 allowed_access_type[v8::ACCESS_GET] = true;
5377 allowed_access_type[v8::ACCESS_SET] = true;
5378
5379 ExpectString("other[42]", "el_getter");
5380 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').get", el_getter);
5381 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').set", el_setter);
5382 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value");
5383
5384 allowed_access_type[v8::ACCESS_SET] = false;
5385 allowed_access_type[v8::ACCESS_GET] = false;
5386 allowed_access_type[v8::ACCESS_HAS] = false;
5387
5213 v8::Handle<Value> value; 5388 v8::Handle<Value> value;
5214 5389
5215 // Access blocked property
5216 value = CompileRun("other.blocked_prop = 1");
5217 value = CompileRun("other.blocked_prop");
5218 CHECK(value->IsUndefined());
5219
5220 value = CompileRun(
5221 "Object.getOwnPropertyDescriptor(other, 'blocked_prop').value");
5222 CHECK(value->IsUndefined());
5223
5224 value = CompileRun("propertyIsEnumerable.call(other, 'blocked_prop')");
5225 CHECK(value->IsFalse());
5226
5227 // Access accessible property 5390 // Access accessible property
5228 value = CompileRun("other.accessible_prop = 3"); 5391 value = CompileRun("other.accessible_prop = 3");
5229 CHECK(value->IsNumber()); 5392 CHECK(value->IsNumber());
5230 CHECK_EQ(3, value->Int32Value()); 5393 CHECK_EQ(3, value->Int32Value());
5231 CHECK_EQ(3, g_echo_value); 5394 CHECK_EQ(3, g_echo_value);
5232 5395
5233 value = CompileRun("other.accessible_prop"); 5396 value = CompileRun("other.accessible_prop");
5234 CHECK(value->IsNumber()); 5397 CHECK(value->IsNumber());
5235 CHECK_EQ(3, value->Int32Value()); 5398 CHECK_EQ(3, value->Int32Value());
5236 5399
(...skipping 6592 matching lines...) Expand 10 before | Expand all | Expand 10 after
11829 v8::Context::Scope context_scope(context.local()); 11992 v8::Context::Scope context_scope(context.local());
11830 11993
11831 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); 11994 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New();
11832 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); 11995 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator);
11833 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); 11996 context->Global()->Set(v8_str("o"), tmpl->NewInstance());
11834 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 11997 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
11835 "var result = []; for (var k in o) result.push(k); result")); 11998 "var result = []; for (var k in o) result.push(k); result"));
11836 CHECK_EQ(1, result->Length()); 11999 CHECK_EQ(1, result->Length());
11837 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); 12000 CHECK_EQ(v8_str("universalAnswer"), result->Get(0));
11838 } 12001 }
OLDNEW
« no previous file with comments | « src/version.cc ('k') | test/mjsunit/get-own-property-descriptor.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698