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

Side by Side Diff: src/objects.cc

Issue 8914: Add support for API accessors that prohibit overwriting by accessors... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 1 month 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
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 2239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 LocalLookupRealNamedProperty(name, result); 2250 LocalLookupRealNamedProperty(name, result);
2251 } 2251 }
2252 2252
2253 2253
2254 void JSObject::Lookup(String* name, LookupResult* result) { 2254 void JSObject::Lookup(String* name, LookupResult* result) {
2255 // Ecma-262 3rd 8.6.2.4 2255 // Ecma-262 3rd 8.6.2.4
2256 for (Object* current = this; 2256 for (Object* current = this;
2257 current != Heap::null_value(); 2257 current != Heap::null_value();
2258 current = JSObject::cast(current)->GetPrototype()) { 2258 current = JSObject::cast(current)->GetPrototype()) {
2259 JSObject::cast(current)->LocalLookup(name, result); 2259 JSObject::cast(current)->LocalLookup(name, result);
2260 if (result->IsValid() && !result->IsTransitionType()) { 2260 if (result->IsValid() && !result->IsTransitionType()) return;
2261 return; 2261 }
2262 } 2262 result->NotFound();
2263 }
2264
2265
2266 // Search object and it's prototype chain for callback properties.
2267 void JSObject::LookupCallback(String* name, LookupResult* result) {
2268 for (Object* current = this;
2269 current != Heap::null_value();
2270 current = JSObject::cast(current)->GetPrototype()) {
2271 JSObject::cast(current)->LocalLookupRealNamedProperty(name, result);
2272 if (result->IsValid() && result->type() == CALLBACKS) return;
2263 } 2273 }
2264 result->NotFound(); 2274 result->NotFound();
2265 } 2275 }
2266 2276
2267 2277
2268 Object* JSObject::DefineGetterSetter(String* name, 2278 Object* JSObject::DefineGetterSetter(String* name,
2269 PropertyAttributes attributes) { 2279 PropertyAttributes attributes) {
2270 // Make sure that the top context does not change when doing callbacks or 2280 // Make sure that the top context does not change when doing callbacks or
2271 // interceptor calls. 2281 // interceptor calls.
2272 AssertNoContextChange ncc; 2282 AssertNoContextChange ncc;
2273 2283
2274 // Check access rights if needed. 2284 // Check access rights if needed.
2275 if (IsAccessCheckNeeded() && 2285 if (IsAccessCheckNeeded() &&
2276 !Top::MayNamedAccess(this, name, v8::ACCESS_SET)) { 2286 !Top::MayNamedAccess(this, name, v8::ACCESS_SET)) {
2277 Top::ReportFailedAccessCheck(this, v8::ACCESS_SET); 2287 Top::ReportFailedAccessCheck(this, v8::ACCESS_SET);
2278 return Heap::undefined_value(); 2288 return Heap::undefined_value();
2279 } 2289 }
2280 2290
2281 // TryFlatten before operating on the string. 2291 // TryFlatten before operating on the string.
2282 name->TryFlatten(); 2292 name->TryFlatten();
2283 2293
2284 // Make sure name is not an index. 2294 // Make sure name is not an index.
2285 uint32_t index; 2295 uint32_t index;
2286 if (name->AsArrayIndex(&index)) return Heap::undefined_value(); 2296 if (name->AsArrayIndex(&index)) return Heap::undefined_value();
2287 2297
2298 // Check if there is an API defined callback object which prohibits
2299 // callback overwriting in this object or it's prototype chain.
2300 // This mechanism is needed for instance in a browser setting, where
2301 // certain accessors such as window.location should not be allowed
2302 // to be overwriten because allowing overwriting could potentially
Kasper Lund 2008/10/30 12:32:27 overwritten
2303 // cause security problems.
2304 LookupResult callback_result;
2305 LookupCallback(name, &callback_result);
2306 if (callback_result.IsValid()) {
2307 Object* obj = callback_result.GetCallbackObject();
2308 if (obj->IsAccessorInfo() &&
2309 AccessorInfo::cast(obj)->prohibits_overwriting()) {
2310 return Heap::undefined_value();
2311 }
2312 }
2313
2288 // Lookup the name. 2314 // Lookup the name.
2289 LookupResult result; 2315 LookupResult result;
2290 LocalLookup(name, &result); 2316 LocalLookup(name, &result);
2291 if (result.IsValid()) { 2317 if (result.IsValid()) {
2292 if (result.IsReadOnly()) return Heap::undefined_value(); 2318 if (result.IsReadOnly()) return Heap::undefined_value();
2293 if (result.type() == CALLBACKS) { 2319 if (result.type() == CALLBACKS) {
2294 Object* obj = result.GetCallbackObject(); 2320 Object* obj = result.GetCallbackObject();
2295 if (obj->IsFixedArray()) return obj; 2321 if (obj->IsFixedArray()) return obj;
2296 } 2322 }
2297 } 2323 }
(...skipping 4487 matching lines...) Expand 10 before | Expand all | Expand 10 after
6785 // No break point. 6811 // No break point.
6786 if (break_point_objects()->IsUndefined()) return 0; 6812 if (break_point_objects()->IsUndefined()) return 0;
6787 // Single beak point. 6813 // Single beak point.
6788 if (!break_point_objects()->IsFixedArray()) return 1; 6814 if (!break_point_objects()->IsFixedArray()) return 1;
6789 // Multiple break points. 6815 // Multiple break points.
6790 return FixedArray::cast(break_point_objects())->length(); 6816 return FixedArray::cast(break_point_objects())->length();
6791 } 6817 }
6792 6818
6793 6819
6794 } } // namespace v8::internal 6820 } } // namespace v8::internal
OLDNEW
« src/apinatives.js ('K') | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698