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

Side by Side Diff: src/runtime.cc

Issue 13533004: Make __proto__ a real JavaScript accessor property. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add regression test for issue 2606. Created 7 years, 8 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/heap.cc ('k') | src/v8natives.js » ('j') | src/v8natives.js » ('J')
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 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 isolate->ReportFailedAccessCheck(JSObject::cast(obj), v8::ACCESS_GET); 1110 isolate->ReportFailedAccessCheck(JSObject::cast(obj), v8::ACCESS_GET);
1111 return isolate->heap()->undefined_value(); 1111 return isolate->heap()->undefined_value();
1112 } 1112 }
1113 obj = obj->GetPrototype(isolate); 1113 obj = obj->GetPrototype(isolate);
1114 } while (obj->IsJSObject() && 1114 } while (obj->IsJSObject() &&
1115 JSObject::cast(obj)->map()->is_hidden_prototype()); 1115 JSObject::cast(obj)->map()->is_hidden_prototype());
1116 return obj; 1116 return obj;
1117 } 1117 }
1118 1118
1119 1119
1120 static inline Object* GetPrototypeSkipHiddenPrototypes(Isolate* isolate,
1121 Object* receiver) {
1122 Object* current = receiver->GetPrototype(isolate);
1123 while (current->IsJSObject() &&
1124 JSObject::cast(current)->map()->is_hidden_prototype()) {
1125 current = current->GetPrototype(isolate);
1126 }
1127 return current;
1128 }
1129
1130
1120 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetPrototype) { 1131 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetPrototype) {
1121 NoHandleAllocation ha(isolate); 1132 NoHandleAllocation ha(isolate);
1122 ASSERT(args.length() == 2); 1133 ASSERT(args.length() == 2);
1123 CONVERT_ARG_CHECKED(JSReceiver, input_obj, 0); 1134 CONVERT_ARG_CHECKED(JSObject, input_obj, 0);
1124 CONVERT_ARG_CHECKED(Object, prototype, 1); 1135 CONVERT_ARG_CHECKED(Object, prototype, 1);
1136 if (FLAG_harmony_observation && input_obj->map()->is_observed()) {
1137 HandleScope scope(isolate);
1138 Handle<JSObject> receiver(input_obj);
1139 Handle<Object> value(prototype, isolate);
1140 Handle<Object> old_value(
1141 GetPrototypeSkipHiddenPrototypes(isolate, *receiver), isolate);
1142
1143 MaybeObject* result = receiver->SetPrototype(*value, true);
1144 Handle<Object> hresult;
1145 if (!result->ToHandle(&hresult, isolate)) return result;
1146
1147 Handle<Object> new_value(
1148 GetPrototypeSkipHiddenPrototypes(isolate, *receiver), isolate);
1149 if (!new_value->SameValue(*old_value)) {
1150 JSObject::EnqueueChangeRecord(receiver, "prototype",
1151 isolate->factory()->proto_string(),
1152 old_value);
1153 }
1154 return *hresult;
1155 }
1125 return input_obj->SetPrototype(prototype, true); 1156 return input_obj->SetPrototype(prototype, true);
1126 } 1157 }
1127 1158
1128 1159
1129 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsInPrototypeChain) { 1160 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsInPrototypeChain) {
1130 NoHandleAllocation ha(isolate); 1161 NoHandleAllocation ha(isolate);
1131 ASSERT(args.length() == 2); 1162 ASSERT(args.length() == 2);
1132 // See ECMA-262, section 15.3.5.3, page 88 (steps 5 - 8). 1163 // See ECMA-262, section 15.3.5.3, page 88 (steps 5 - 8).
1133 Object* O = args[0]; 1164 Object* O = args[0];
1134 Object* V = args[1]; 1165 Object* V = args[1];
(...skipping 3109 matching lines...) Expand 10 before | Expand all | Expand 10 after
4244 4275
4245 // Special case for callback properties. 4276 // Special case for callback properties.
4246 if (result.IsPropertyCallbacks()) { 4277 if (result.IsPropertyCallbacks()) {
4247 Object* callback = result.GetCallbackObject(); 4278 Object* callback = result.GetCallbackObject();
4248 // To be compatible with Safari we do not change the value on API objects 4279 // To be compatible with Safari we do not change the value on API objects
4249 // in Object.defineProperty(). Firefox disagrees here, and actually changes 4280 // in Object.defineProperty(). Firefox disagrees here, and actually changes
4250 // the value. 4281 // the value.
4251 if (callback->IsAccessorInfo()) { 4282 if (callback->IsAccessorInfo()) {
4252 return isolate->heap()->undefined_value(); 4283 return isolate->heap()->undefined_value();
4253 } 4284 }
4254 // TODO(mstarzinger): The __proto__ property should actually be a real
4255 // JavaScript accessor instead of a foreign callback. But for now we just
4256 // avoid changing the writability and configurability attribute of this
4257 // property.
4258 Handle<Name> proto_string = isolate->factory()->proto_string();
4259 if (callback->IsForeign() && proto_string->Equals(*name)) {
4260 attr = static_cast<PropertyAttributes>(attr & ~(READ_ONLY | DONT_DELETE));
4261 }
4262 // Avoid redefining foreign callback as data property, just use the stored 4285 // Avoid redefining foreign callback as data property, just use the stored
4263 // setter to update the value instead. 4286 // setter to update the value instead.
4264 // TODO(mstarzinger): So far this only works if property attributes don't 4287 // TODO(mstarzinger): So far this only works if property attributes don't
4265 // change, this should be fixed once we cleanup the underlying code. 4288 // change, this should be fixed once we cleanup the underlying code.
4266 if (callback->IsForeign() && result.GetAttributes() == attr) { 4289 if (callback->IsForeign() && result.GetAttributes() == attr) {
4267 return js_object->SetPropertyWithCallback(callback, 4290 return js_object->SetPropertyWithCallback(callback,
4268 *name, 4291 *name,
4269 *obj_value, 4292 *obj_value,
4270 result.holder(), 4293 result.holder(),
4271 kStrictMode); 4294 kStrictMode);
(...skipping 7888 matching lines...) Expand 10 before | Expand all | Expand 10 after
12160 } 12183 }
12161 return JSArray::cast(result)->SetContent(instances); 12184 return JSArray::cast(result)->SetContent(instances);
12162 } 12185 }
12163 12186
12164 12187
12165 // Find the effective prototype object as returned by __proto__. 12188 // Find the effective prototype object as returned by __proto__.
12166 // args[0]: the object to find the prototype for. 12189 // args[0]: the object to find the prototype for.
12167 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetPrototype) { 12190 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetPrototype) {
12168 NoHandleAllocation ha(isolate); 12191 NoHandleAllocation ha(isolate);
12169 ASSERT(args.length() == 1); 12192 ASSERT(args.length() == 1);
12170
12171 CONVERT_ARG_CHECKED(JSObject, obj, 0); 12193 CONVERT_ARG_CHECKED(JSObject, obj, 0);
12172 12194 return GetPrototypeSkipHiddenPrototypes(isolate, obj);
12173 // Use the __proto__ accessor.
12174 return Accessors::ObjectPrototype.getter(obj, NULL);
12175 } 12195 }
12176 12196
12177 12197
12178 // Patches script source (should be called upon BeforeCompile event). 12198 // Patches script source (should be called upon BeforeCompile event).
12179 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugSetScriptSource) { 12199 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugSetScriptSource) {
12180 HandleScope scope(isolate); 12200 HandleScope scope(isolate);
12181 ASSERT(args.length() == 2); 12201 ASSERT(args.length() == 2);
12182 12202
12183 CONVERT_ARG_HANDLE_CHECKED(JSValue, script_wrapper, 0); 12203 CONVERT_ARG_HANDLE_CHECKED(JSValue, script_wrapper, 0);
12184 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); 12204 CONVERT_ARG_HANDLE_CHECKED(String, source, 1);
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
13151 // Handle last resort GC and make sure to allow future allocations 13171 // Handle last resort GC and make sure to allow future allocations
13152 // to grow the heap without causing GCs (if possible). 13172 // to grow the heap without causing GCs (if possible).
13153 isolate->counters()->gc_last_resort_from_js()->Increment(); 13173 isolate->counters()->gc_last_resort_from_js()->Increment();
13154 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13174 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13155 "Runtime::PerformGC"); 13175 "Runtime::PerformGC");
13156 } 13176 }
13157 } 13177 }
13158 13178
13159 13179
13160 } } // namespace v8::internal 13180 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | src/v8natives.js » ('j') | src/v8natives.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698