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

Side by Side Diff: src/v8natives.js

Issue 201114: Implemented Object.keys. (Closed)
Patch Set: try-again Created 11 years, 3 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
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/testcfg.py » ('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 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 269
270 270
271 function ObjectLookupSetter(name) { 271 function ObjectLookupSetter(name) {
272 if (this == null) { 272 if (this == null) {
273 throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); 273 throw new $TypeError('Object.prototype.__lookupSetter__: this is Null');
274 } 274 }
275 return %LookupAccessor(ToObject(this), ToString(name), SETTER); 275 return %LookupAccessor(ToObject(this), ToString(name), SETTER);
276 } 276 }
277 277
278 278
279 function ObjectKeys(obj) {
280 if (!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj))
281 throw MakeTypeError('object_keys_non_object', [obj]);
282 return %LocalKeys(obj);
283 }
284
285
279 %SetCode($Object, function(x) { 286 %SetCode($Object, function(x) {
280 if (%_IsConstructCall()) { 287 if (%_IsConstructCall()) {
281 if (x == null) return this; 288 if (x == null) return this;
282 return ToObject(x); 289 return ToObject(x);
283 } else { 290 } else {
284 if (x == null) return { }; 291 if (x == null) return { };
285 return ToObject(x); 292 return ToObject(x);
286 } 293 }
287 }); 294 });
288 295
289 296
290 // ---------------------------------------------------------------------------- 297 // ----------------------------------------------------------------------------
291 298
292 299
293 function SetupObject() { 300 function SetupObject() {
294 // Setup non-enumerable functions on the Object.prototype object. 301 // Setup non-enumerable functions on the Object.prototype object.
295 InstallFunctions($Object.prototype, DONT_ENUM, $Array( 302 InstallFunctions($Object.prototype, DONT_ENUM, $Array(
296 "toString", ObjectToString, 303 "toString", ObjectToString,
297 "toLocaleString", ObjectToLocaleString, 304 "toLocaleString", ObjectToLocaleString,
298 "valueOf", ObjectValueOf, 305 "valueOf", ObjectValueOf,
299 "hasOwnProperty", ObjectHasOwnProperty, 306 "hasOwnProperty", ObjectHasOwnProperty,
300 "isPrototypeOf", ObjectIsPrototypeOf, 307 "isPrototypeOf", ObjectIsPrototypeOf,
301 "propertyIsEnumerable", ObjectPropertyIsEnumerable, 308 "propertyIsEnumerable", ObjectPropertyIsEnumerable,
302 "__defineGetter__", ObjectDefineGetter, 309 "__defineGetter__", ObjectDefineGetter,
303 "__lookupGetter__", ObjectLookupGetter, 310 "__lookupGetter__", ObjectLookupGetter,
304 "__defineSetter__", ObjectDefineSetter, 311 "__defineSetter__", ObjectDefineSetter,
305 "__lookupSetter__", ObjectLookupSetter 312 "__lookupSetter__", ObjectLookupSetter
306 )); 313 ));
314 InstallFunctions($Object, DONT_ENUM, $Array(
315 "keys", ObjectKeys
316 ));
307 } 317 }
308 318
309 SetupObject(); 319 SetupObject();
310 320
311 321
312 // ---------------------------------------------------------------------------- 322 // ----------------------------------------------------------------------------
313 // Boolean 323 // Boolean
314 324
315 function BooleanToString() { 325 function BooleanToString() {
316 // NOTE: Both Boolean objects and values can enter here as 326 // NOTE: Both Boolean objects and values can enter here as
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 579
570 // ---------------------------------------------------------------------------- 580 // ----------------------------------------------------------------------------
571 581
572 function SetupFunction() { 582 function SetupFunction() {
573 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 583 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
574 "toString", FunctionToString 584 "toString", FunctionToString
575 )); 585 ));
576 } 586 }
577 587
578 SetupFunction(); 588 SetupFunction();
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/testcfg.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698