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

Unified 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, 2 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 side-by-side diff with in-line comments
Download patch
« src/apinatives.js ('K') | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
===================================================================
--- src/objects.cc (revision 654)
+++ src/objects.cc (working copy)
@@ -2257,14 +2257,24 @@
current != Heap::null_value();
current = JSObject::cast(current)->GetPrototype()) {
JSObject::cast(current)->LocalLookup(name, result);
- if (result->IsValid() && !result->IsTransitionType()) {
- return;
- }
+ if (result->IsValid() && !result->IsTransitionType()) return;
}
result->NotFound();
}
+// Search object and it's prototype chain for callback properties.
+void JSObject::LookupCallback(String* name, LookupResult* result) {
+ for (Object* current = this;
+ current != Heap::null_value();
+ current = JSObject::cast(current)->GetPrototype()) {
+ JSObject::cast(current)->LocalLookupRealNamedProperty(name, result);
+ if (result->IsValid() && result->type() == CALLBACKS) return;
+ }
+ result->NotFound();
+}
+
+
Object* JSObject::DefineGetterSetter(String* name,
PropertyAttributes attributes) {
// Make sure that the top context does not change when doing callbacks or
@@ -2285,6 +2295,22 @@
uint32_t index;
if (name->AsArrayIndex(&index)) return Heap::undefined_value();
+ // Check if there is an API defined callback object which prohibits
+ // callback overwriting in this object or it's prototype chain.
+ // This mechanism is needed for instance in a browser setting, where
+ // certain accessors such as window.location should not be allowed
+ // to be overwriten because allowing overwriting could potentially
Kasper Lund 2008/10/30 12:32:27 overwritten
+ // cause security problems.
+ LookupResult callback_result;
+ LookupCallback(name, &callback_result);
+ if (callback_result.IsValid()) {
+ Object* obj = callback_result.GetCallbackObject();
+ if (obj->IsAccessorInfo() &&
+ AccessorInfo::cast(obj)->prohibits_overwriting()) {
+ return Heap::undefined_value();
+ }
+ }
+
// Lookup the name.
LookupResult result;
LocalLookup(name, &result);
« 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