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

Side by Side Diff: src/v8natives.js

Issue 651223002: Implement inline %_IsJSProxy() for full codegen and Hydrogen (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime/runtime-proxy.cc ('k') | src/x64/full-codegen-x64.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file relies on the fact that the following declarations have been made 5 // This file relies on the fact that the following declarations have been made
6 // in runtime.js: 6 // in runtime.js:
7 // var $Object = global.Object; 7 // var $Object = global.Object;
8 // var $Boolean = global.Boolean; 8 // var $Boolean = global.Boolean;
9 // var $Number = global.Number; 9 // var $Number = global.Number;
10 // var $Function = global.Function; 10 // var $Function = global.Function;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 231
232 232
233 // ECMA-262 - 15.2.4.4 233 // ECMA-262 - 15.2.4.4
234 function ObjectValueOf() { 234 function ObjectValueOf() {
235 return ToObject(this); 235 return ToObject(this);
236 } 236 }
237 237
238 238
239 // ECMA-262 - 15.2.4.5 239 // ECMA-262 - 15.2.4.5
240 function ObjectHasOwnProperty(V) { 240 function ObjectHasOwnProperty(V) {
241 if (%IsJSProxy(this)) { 241 if (%_IsJSProxy(this)) {
242 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 242 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
243 if (IS_SYMBOL(V)) return false; 243 if (IS_SYMBOL(V)) return false;
244 244
245 var handler = %GetHandler(this); 245 var handler = %GetHandler(this);
246 return CallTrap1(handler, "hasOwn", DerivedHasOwnTrap, ToName(V)); 246 return CallTrap1(handler, "hasOwn", DerivedHasOwnTrap, ToName(V));
247 } 247 }
248 return %HasOwnProperty(TO_OBJECT_INLINE(this), ToName(V)); 248 return %HasOwnProperty(TO_OBJECT_INLINE(this), ToName(V));
249 } 249 }
250 250
251 251
252 // ECMA-262 - 15.2.4.6 252 // ECMA-262 - 15.2.4.6
253 function ObjectIsPrototypeOf(V) { 253 function ObjectIsPrototypeOf(V) {
254 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.isPrototypeOf"); 254 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.isPrototypeOf");
255 if (!IS_SPEC_OBJECT(V)) return false; 255 if (!IS_SPEC_OBJECT(V)) return false;
256 return %IsInPrototypeChain(this, V); 256 return %IsInPrototypeChain(this, V);
257 } 257 }
258 258
259 259
260 // ECMA-262 - 15.2.4.6 260 // ECMA-262 - 15.2.4.6
261 function ObjectPropertyIsEnumerable(V) { 261 function ObjectPropertyIsEnumerable(V) {
262 var P = ToName(V); 262 var P = ToName(V);
263 if (%IsJSProxy(this)) { 263 if (%_IsJSProxy(this)) {
264 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 264 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
265 if (IS_SYMBOL(V)) return false; 265 if (IS_SYMBOL(V)) return false;
266 266
267 var desc = GetOwnPropertyJS(this, P); 267 var desc = GetOwnPropertyJS(this, P);
268 return IS_UNDEFINED(desc) ? false : desc.isEnumerable(); 268 return IS_UNDEFINED(desc) ? false : desc.isEnumerable();
269 } 269 }
270 return %IsPropertyEnumerable(ToObject(this), P); 270 return %IsPropertyEnumerable(ToObject(this), P);
271 } 271 }
272 272
273 273
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 var receiver = this; 319 var receiver = this;
320 if (receiver == null && !IS_UNDETECTABLE(receiver)) { 320 if (receiver == null && !IS_UNDETECTABLE(receiver)) {
321 receiver = %GlobalProxy(global); 321 receiver = %GlobalProxy(global);
322 } 322 }
323 return %LookupAccessor(ToObject(receiver), ToName(name), SETTER); 323 return %LookupAccessor(ToObject(receiver), ToName(name), SETTER);
324 } 324 }
325 325
326 326
327 function ObjectKeys(obj) { 327 function ObjectKeys(obj) {
328 obj = ToObject(obj); 328 obj = ToObject(obj);
329 if (%IsJSProxy(obj)) { 329 if (%_IsJSProxy(obj)) {
330 var handler = %GetHandler(obj); 330 var handler = %GetHandler(obj);
331 var names = CallTrap0(handler, "keys", DerivedKeysTrap); 331 var names = CallTrap0(handler, "keys", DerivedKeysTrap);
332 return ToNameArray(names, "keys", false); 332 return ToNameArray(names, "keys", false);
333 } 333 }
334 return %OwnKeys(obj); 334 return %OwnKeys(obj);
335 } 335 }
336 336
337 337
338 // ES5 8.10.1. 338 // ES5 8.10.1.
339 function IsAccessorDescriptor(desc) { 339 function IsAccessorDescriptor(desc) {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 616
617 617
618 function CallTrap2(handler, name, defaultTrap, x, y) { 618 function CallTrap2(handler, name, defaultTrap, x, y) {
619 return %_CallFunction(handler, x, y, GetTrap(handler, name, defaultTrap)); 619 return %_CallFunction(handler, x, y, GetTrap(handler, name, defaultTrap));
620 } 620 }
621 621
622 622
623 // ES5 section 8.12.1. 623 // ES5 section 8.12.1.
624 function GetOwnPropertyJS(obj, v) { 624 function GetOwnPropertyJS(obj, v) {
625 var p = ToName(v); 625 var p = ToName(v);
626 if (%IsJSProxy(obj)) { 626 if (%_IsJSProxy(obj)) {
627 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 627 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
628 if (IS_SYMBOL(v)) return UNDEFINED; 628 if (IS_SYMBOL(v)) return UNDEFINED;
629 629
630 var handler = %GetHandler(obj); 630 var handler = %GetHandler(obj);
631 var descriptor = CallTrap1( 631 var descriptor = CallTrap1(
632 handler, "getOwnPropertyDescriptor", UNDEFINED, p); 632 handler, "getOwnPropertyDescriptor", UNDEFINED, p);
633 if (IS_UNDEFINED(descriptor)) return descriptor; 633 if (IS_UNDEFINED(descriptor)) return descriptor;
634 var desc = ToCompletePropertyDescriptor(descriptor); 634 var desc = ToCompletePropertyDescriptor(descriptor);
635 if (!desc.isConfigurable()) { 635 if (!desc.isConfigurable()) {
636 throw MakeTypeError("proxy_prop_not_configurable", 636 throw MakeTypeError("proxy_prop_not_configurable",
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 } 956 }
957 } 957 }
958 958
959 // Step 5 - Fallback to default implementation. 959 // Step 5 - Fallback to default implementation.
960 return DefineObjectProperty(obj, p, desc, should_throw); 960 return DefineObjectProperty(obj, p, desc, should_throw);
961 } 961 }
962 962
963 963
964 // ES5 section 8.12.9, ES5 section 15.4.5.1 and Harmony proxies. 964 // ES5 section 8.12.9, ES5 section 15.4.5.1 and Harmony proxies.
965 function DefineOwnProperty(obj, p, desc, should_throw) { 965 function DefineOwnProperty(obj, p, desc, should_throw) {
966 if (%IsJSProxy(obj)) { 966 if (%_IsJSProxy(obj)) {
967 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 967 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
968 if (IS_SYMBOL(p)) return false; 968 if (IS_SYMBOL(p)) return false;
969 969
970 var attributes = FromGenericPropertyDescriptor(desc); 970 var attributes = FromGenericPropertyDescriptor(desc);
971 return DefineProxyProperty(obj, p, attributes, should_throw); 971 return DefineProxyProperty(obj, p, attributes, should_throw);
972 } else if (IS_ARRAY(obj)) { 972 } else if (IS_ARRAY(obj)) {
973 return DefineArrayProperty(obj, p, desc, should_throw); 973 return DefineArrayProperty(obj, p, desc, should_throw);
974 } else { 974 } else {
975 return DefineObjectProperty(obj, p, desc, should_throw); 975 return DefineObjectProperty(obj, p, desc, should_throw);
976 } 976 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 return propertyNames; 1104 return propertyNames;
1105 } 1105 }
1106 1106
1107 1107
1108 // ES5 section 15.2.3.4. 1108 // ES5 section 15.2.3.4.
1109 function ObjectGetOwnPropertyNames(obj) { 1109 function ObjectGetOwnPropertyNames(obj) {
1110 if (!IS_SPEC_OBJECT(obj)) { 1110 if (!IS_SPEC_OBJECT(obj)) {
1111 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); 1111 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]);
1112 } 1112 }
1113 // Special handling for proxies. 1113 // Special handling for proxies.
1114 if (%IsJSProxy(obj)) { 1114 if (%_IsJSProxy(obj)) {
1115 var handler = %GetHandler(obj); 1115 var handler = %GetHandler(obj);
1116 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED); 1116 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED);
1117 return ToNameArray(names, "getOwnPropertyNames", false); 1117 return ToNameArray(names, "getOwnPropertyNames", false);
1118 } 1118 }
1119 1119
1120 return ObjectGetOwnPropertyKeys(obj, false); 1120 return ObjectGetOwnPropertyKeys(obj, false);
1121 } 1121 }
1122 1122
1123 1123
1124 // ES5 section 15.2.3.5. 1124 // ES5 section 15.2.3.5.
1125 function ObjectCreate(proto, properties) { 1125 function ObjectCreate(proto, properties) {
1126 if (!IS_SPEC_OBJECT(proto) && proto !== null) { 1126 if (!IS_SPEC_OBJECT(proto) && proto !== null) {
1127 throw MakeTypeError("proto_object_or_null", [proto]); 1127 throw MakeTypeError("proto_object_or_null", [proto]);
1128 } 1128 }
1129 var obj = {}; 1129 var obj = {};
1130 %InternalSetPrototype(obj, proto); 1130 %InternalSetPrototype(obj, proto);
1131 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); 1131 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties);
1132 return obj; 1132 return obj;
1133 } 1133 }
1134 1134
1135 1135
1136 // ES5 section 15.2.3.6. 1136 // ES5 section 15.2.3.6.
1137 function ObjectDefineProperty(obj, p, attributes) { 1137 function ObjectDefineProperty(obj, p, attributes) {
1138 if (!IS_SPEC_OBJECT(obj)) { 1138 if (!IS_SPEC_OBJECT(obj)) {
1139 throw MakeTypeError("called_on_non_object", ["Object.defineProperty"]); 1139 throw MakeTypeError("called_on_non_object", ["Object.defineProperty"]);
1140 } 1140 }
1141 var name = ToName(p); 1141 var name = ToName(p);
1142 if (%IsJSProxy(obj)) { 1142 if (%_IsJSProxy(obj)) {
1143 // Clone the attributes object for protection. 1143 // Clone the attributes object for protection.
1144 // TODO(rossberg): not spec'ed yet, so not sure if this should involve 1144 // TODO(rossberg): not spec'ed yet, so not sure if this should involve
1145 // non-own properties as it does (or non-enumerable ones, as it doesn't?). 1145 // non-own properties as it does (or non-enumerable ones, as it doesn't?).
1146 var attributesClone = { __proto__: null }; 1146 var attributesClone = { __proto__: null };
1147 for (var a in attributes) { 1147 for (var a in attributes) {
1148 attributesClone[a] = attributes[a]; 1148 attributesClone[a] = attributes[a];
1149 } 1149 }
1150 DefineProxyProperty(obj, name, attributesClone, true); 1150 DefineProxyProperty(obj, name, attributesClone, true);
1151 // The following would implement the spec as in the current proposal, 1151 // The following would implement the spec as in the current proposal,
1152 // but after recent comments on es-discuss, is most likely obsolete. 1152 // but after recent comments on es-discuss, is most likely obsolete.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 } 1241 }
1242 ObjectDefineProperties(obj, props); 1242 ObjectDefineProperties(obj, props);
1243 } 1243 }
1244 1244
1245 1245
1246 // ES5 section 15.2.3.8. 1246 // ES5 section 15.2.3.8.
1247 function ObjectSeal(obj) { 1247 function ObjectSeal(obj) {
1248 if (!IS_SPEC_OBJECT(obj)) { 1248 if (!IS_SPEC_OBJECT(obj)) {
1249 throw MakeTypeError("called_on_non_object", ["Object.seal"]); 1249 throw MakeTypeError("called_on_non_object", ["Object.seal"]);
1250 } 1250 }
1251 if (%IsJSProxy(obj)) { 1251 if (%_IsJSProxy(obj)) {
1252 ProxyFix(obj); 1252 ProxyFix(obj);
1253 } 1253 }
1254 var names = ObjectGetOwnPropertyNames(obj); 1254 var names = ObjectGetOwnPropertyNames(obj);
1255 for (var i = 0; i < names.length; i++) { 1255 for (var i = 0; i < names.length; i++) {
1256 var name = names[i]; 1256 var name = names[i];
1257 var desc = GetOwnPropertyJS(obj, name); 1257 var desc = GetOwnPropertyJS(obj, name);
1258 if (desc.isConfigurable()) { 1258 if (desc.isConfigurable()) {
1259 desc.setConfigurable(false); 1259 desc.setConfigurable(false);
1260 DefineOwnProperty(obj, name, desc, true); 1260 DefineOwnProperty(obj, name, desc, true);
1261 } 1261 }
1262 } 1262 }
1263 %PreventExtensions(obj); 1263 %PreventExtensions(obj);
1264 return obj; 1264 return obj;
1265 } 1265 }
1266 1266
1267 1267
1268 // ES5 section 15.2.3.9. 1268 // ES5 section 15.2.3.9.
1269 function ObjectFreezeJS(obj) { 1269 function ObjectFreezeJS(obj) {
1270 if (!IS_SPEC_OBJECT(obj)) { 1270 if (!IS_SPEC_OBJECT(obj)) {
1271 throw MakeTypeError("called_on_non_object", ["Object.freeze"]); 1271 throw MakeTypeError("called_on_non_object", ["Object.freeze"]);
1272 } 1272 }
1273 var isProxy = %IsJSProxy(obj); 1273 var isProxy = %_IsJSProxy(obj);
1274 if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) { 1274 if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) {
1275 if (isProxy) { 1275 if (isProxy) {
1276 ProxyFix(obj); 1276 ProxyFix(obj);
1277 } 1277 }
1278 var names = ObjectGetOwnPropertyNames(obj); 1278 var names = ObjectGetOwnPropertyNames(obj);
1279 for (var i = 0; i < names.length; i++) { 1279 for (var i = 0; i < names.length; i++) {
1280 var name = names[i]; 1280 var name = names[i];
1281 var desc = GetOwnPropertyJS(obj, name); 1281 var desc = GetOwnPropertyJS(obj, name);
1282 if (desc.isWritable() || desc.isConfigurable()) { 1282 if (desc.isWritable() || desc.isConfigurable()) {
1283 if (IsDataDescriptor(desc)) desc.setWritable(false); 1283 if (IsDataDescriptor(desc)) desc.setWritable(false);
1284 desc.setConfigurable(false); 1284 desc.setConfigurable(false);
1285 DefineOwnProperty(obj, name, desc, true); 1285 DefineOwnProperty(obj, name, desc, true);
1286 } 1286 }
1287 } 1287 }
1288 %PreventExtensions(obj); 1288 %PreventExtensions(obj);
1289 } else { 1289 } else {
1290 // TODO(adamk): Is it worth going to this fast path if the 1290 // TODO(adamk): Is it worth going to this fast path if the
1291 // object's properties are already in dictionary mode? 1291 // object's properties are already in dictionary mode?
1292 %ObjectFreeze(obj); 1292 %ObjectFreeze(obj);
1293 } 1293 }
1294 return obj; 1294 return obj;
1295 } 1295 }
1296 1296
1297 1297
1298 // ES5 section 15.2.3.10 1298 // ES5 section 15.2.3.10
1299 function ObjectPreventExtension(obj) { 1299 function ObjectPreventExtension(obj) {
1300 if (!IS_SPEC_OBJECT(obj)) { 1300 if (!IS_SPEC_OBJECT(obj)) {
1301 throw MakeTypeError("called_on_non_object", ["Object.preventExtension"]); 1301 throw MakeTypeError("called_on_non_object", ["Object.preventExtension"]);
1302 } 1302 }
1303 if (%IsJSProxy(obj)) { 1303 if (%_IsJSProxy(obj)) {
1304 ProxyFix(obj); 1304 ProxyFix(obj);
1305 } 1305 }
1306 %PreventExtensions(obj); 1306 %PreventExtensions(obj);
1307 return obj; 1307 return obj;
1308 } 1308 }
1309 1309
1310 1310
1311 // ES5 section 15.2.3.11 1311 // ES5 section 15.2.3.11
1312 function ObjectIsSealed(obj) { 1312 function ObjectIsSealed(obj) {
1313 if (!IS_SPEC_OBJECT(obj)) { 1313 if (!IS_SPEC_OBJECT(obj)) {
1314 throw MakeTypeError("called_on_non_object", ["Object.isSealed"]); 1314 throw MakeTypeError("called_on_non_object", ["Object.isSealed"]);
1315 } 1315 }
1316 if (%IsJSProxy(obj)) { 1316 if (%_IsJSProxy(obj)) {
1317 return false; 1317 return false;
1318 } 1318 }
1319 if (%IsExtensible(obj)) { 1319 if (%IsExtensible(obj)) {
1320 return false; 1320 return false;
1321 } 1321 }
1322 var names = ObjectGetOwnPropertyNames(obj); 1322 var names = ObjectGetOwnPropertyNames(obj);
1323 for (var i = 0; i < names.length; i++) { 1323 for (var i = 0; i < names.length; i++) {
1324 var name = names[i]; 1324 var name = names[i];
1325 var desc = GetOwnPropertyJS(obj, name); 1325 var desc = GetOwnPropertyJS(obj, name);
1326 if (desc.isConfigurable()) { 1326 if (desc.isConfigurable()) {
1327 return false; 1327 return false;
1328 } 1328 }
1329 } 1329 }
1330 return true; 1330 return true;
1331 } 1331 }
1332 1332
1333 1333
1334 // ES5 section 15.2.3.12 1334 // ES5 section 15.2.3.12
1335 function ObjectIsFrozen(obj) { 1335 function ObjectIsFrozen(obj) {
1336 if (!IS_SPEC_OBJECT(obj)) { 1336 if (!IS_SPEC_OBJECT(obj)) {
1337 throw MakeTypeError("called_on_non_object", ["Object.isFrozen"]); 1337 throw MakeTypeError("called_on_non_object", ["Object.isFrozen"]);
1338 } 1338 }
1339 if (%IsJSProxy(obj)) { 1339 if (%_IsJSProxy(obj)) {
1340 return false; 1340 return false;
1341 } 1341 }
1342 if (%IsExtensible(obj)) { 1342 if (%IsExtensible(obj)) {
1343 return false; 1343 return false;
1344 } 1344 }
1345 var names = ObjectGetOwnPropertyNames(obj); 1345 var names = ObjectGetOwnPropertyNames(obj);
1346 for (var i = 0; i < names.length; i++) { 1346 for (var i = 0; i < names.length; i++) {
1347 var name = names[i]; 1347 var name = names[i];
1348 var desc = GetOwnPropertyJS(obj, name); 1348 var desc = GetOwnPropertyJS(obj, name);
1349 if (IsDataDescriptor(desc) && desc.isWritable()) return false; 1349 if (IsDataDescriptor(desc) && desc.isWritable()) return false;
1350 if (desc.isConfigurable()) return false; 1350 if (desc.isConfigurable()) return false;
1351 } 1351 }
1352 return true; 1352 return true;
1353 } 1353 }
1354 1354
1355 1355
1356 // ES5 section 15.2.3.13 1356 // ES5 section 15.2.3.13
1357 function ObjectIsExtensible(obj) { 1357 function ObjectIsExtensible(obj) {
1358 if (!IS_SPEC_OBJECT(obj)) { 1358 if (!IS_SPEC_OBJECT(obj)) {
1359 throw MakeTypeError("called_on_non_object", ["Object.isExtensible"]); 1359 throw MakeTypeError("called_on_non_object", ["Object.isExtensible"]);
1360 } 1360 }
1361 if (%IsJSProxy(obj)) { 1361 if (%_IsJSProxy(obj)) {
1362 return true; 1362 return true;
1363 } 1363 }
1364 return %IsExtensible(obj); 1364 return %IsExtensible(obj);
1365 } 1365 }
1366 1366
1367 1367
1368 // Harmony egal. 1368 // Harmony egal.
1369 function ObjectIs(obj1, obj2) { 1369 function ObjectIs(obj1, obj2) {
1370 if (obj1 === obj2) { 1370 if (obj1 === obj2) {
1371 return (obj1 !== 0) || (1 / obj1 === 1 / obj2); 1371 return (obj1 !== 0) || (1 / obj1 === 1 / obj2);
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1907 } 1907 }
1908 if (!IS_SPEC_FUNCTION(method)) { 1908 if (!IS_SPEC_FUNCTION(method)) {
1909 throw MakeTypeError('not_iterable', [obj]); 1909 throw MakeTypeError('not_iterable', [obj]);
1910 } 1910 }
1911 var iterator = %_CallFunction(obj, method); 1911 var iterator = %_CallFunction(obj, method);
1912 if (!IS_SPEC_OBJECT(iterator)) { 1912 if (!IS_SPEC_OBJECT(iterator)) {
1913 throw MakeTypeError('not_an_iterator', [iterator]); 1913 throw MakeTypeError('not_an_iterator', [iterator]);
1914 } 1914 }
1915 return iterator; 1915 return iterator;
1916 } 1916 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-proxy.cc ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698