Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 | 244 |
| 245 | 245 |
| 246 // Extensions for providing property getters and setters. | 246 // Extensions for providing property getters and setters. |
| 247 function ObjectDefineGetter(name, fun) { | 247 function ObjectDefineGetter(name, fun) { |
| 248 if (this == null && !IS_UNDETECTABLE(this)) { | 248 if (this == null && !IS_UNDETECTABLE(this)) { |
| 249 throw new $TypeError('Object.prototype.__defineGetter__: this is Null'); | 249 throw new $TypeError('Object.prototype.__defineGetter__: this is Null'); |
| 250 } | 250 } |
| 251 if (!IS_FUNCTION(fun)) { | 251 if (!IS_FUNCTION(fun)) { |
| 252 throw new $TypeError('Object.prototype.__defineGetter__: Expecting function' ); | 252 throw new $TypeError('Object.prototype.__defineGetter__: Expecting function' ); |
| 253 } | 253 } |
| 254 return %DefineAccessor(ToObject(this), ToString(name), GETTER, fun); | 254 var desc = { get: fun, enumerable: true, configurable: true }; |
| 255 desc = ToPropertyDescriptor(desc); | |
|
Lasse Reichstein
2011/03/11 07:52:35
Why not
var desc = new PropertyDescriptor();
des
Rico
2011/03/11 08:05:48
Done.
| |
| 256 DefineOwnProperty(ToObject(this), ToString(name), desc, true); | |
| 255 } | 257 } |
| 256 | 258 |
| 257 | 259 |
| 258 function ObjectLookupGetter(name) { | 260 function ObjectLookupGetter(name) { |
| 259 if (this == null && !IS_UNDETECTABLE(this)) { | 261 if (this == null && !IS_UNDETECTABLE(this)) { |
| 260 throw new $TypeError('Object.prototype.__lookupGetter__: this is Null'); | 262 throw new $TypeError('Object.prototype.__lookupGetter__: this is Null'); |
| 261 } | 263 } |
| 262 return %LookupAccessor(ToObject(this), ToString(name), GETTER); | 264 return %LookupAccessor(ToObject(this), ToString(name), GETTER); |
| 263 } | 265 } |
| 264 | 266 |
| 265 | 267 |
| 266 function ObjectDefineSetter(name, fun) { | 268 function ObjectDefineSetter(name, fun) { |
| 267 if (this == null && !IS_UNDETECTABLE(this)) { | 269 if (this == null && !IS_UNDETECTABLE(this)) { |
| 268 throw new $TypeError('Object.prototype.__defineSetter__: this is Null'); | 270 throw new $TypeError('Object.prototype.__defineSetter__: this is Null'); |
| 269 } | 271 } |
| 270 if (!IS_FUNCTION(fun)) { | 272 if (!IS_FUNCTION(fun)) { |
| 271 throw new $TypeError( | 273 throw new $TypeError( |
| 272 'Object.prototype.__defineSetter__: Expecting function'); | 274 'Object.prototype.__defineSetter__: Expecting function'); |
| 273 } | 275 } |
| 274 return %DefineAccessor(ToObject(this), ToString(name), SETTER, fun); | 276 var desc = { set: fun, enumerable: true, configurable: true }; |
|
Lasse Reichstein
2011/03/11 07:52:35
Ditto.
Rico
2011/03/11 08:05:48
Done.
| |
| 277 desc = ToPropertyDescriptor(desc); | |
| 278 DefineOwnProperty(ToObject(this), ToString(name), desc, true); | |
| 275 } | 279 } |
| 276 | 280 |
| 277 | 281 |
| 278 function ObjectLookupSetter(name) { | 282 function ObjectLookupSetter(name) { |
| 279 if (this == null && !IS_UNDETECTABLE(this)) { | 283 if (this == null && !IS_UNDETECTABLE(this)) { |
| 280 throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); | 284 throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); |
| 281 } | 285 } |
| 282 return %LookupAccessor(ToObject(this), ToString(name), SETTER); | 286 return %LookupAccessor(ToObject(this), ToString(name), SETTER); |
| 283 } | 287 } |
| 284 | 288 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 this.enumerable_ = false; | 391 this.enumerable_ = false; |
| 388 this.hasEnumerable_ = false; | 392 this.hasEnumerable_ = false; |
| 389 this.configurable_ = false; | 393 this.configurable_ = false; |
| 390 this.hasConfigurable_ = false; | 394 this.hasConfigurable_ = false; |
| 391 this.get_ = void 0; | 395 this.get_ = void 0; |
| 392 this.hasGetter_ = false; | 396 this.hasGetter_ = false; |
| 393 this.set_ = void 0; | 397 this.set_ = void 0; |
| 394 this.hasSetter_ = false; | 398 this.hasSetter_ = false; |
| 395 } | 399 } |
| 396 | 400 |
| 401 //PropertyDescriptor.prototype.__proto__ = null; | |
|
Lasse Reichstein
2011/03/11 07:52:35
Uncomment this! :)
And add:
PropertyDescriptor.pro
Rico
2011/03/11 08:05:48
Ups, sorry, and done
| |
| 397 | 402 |
| 398 PropertyDescriptor.prototype.setValue = function(value) { | 403 PropertyDescriptor.prototype.setValue = function(value) { |
| 399 this.value_ = value; | 404 this.value_ = value; |
| 400 this.hasValue_ = true; | 405 this.hasValue_ = true; |
| 401 } | 406 } |
| 402 | 407 |
| 403 | 408 |
| 404 PropertyDescriptor.prototype.getValue = function() { | 409 PropertyDescriptor.prototype.getValue = function() { |
| 405 return this.value_; | 410 return this.value_; |
| 406 } | 411 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 | 493 |
| 489 PropertyDescriptor.prototype.hasSetter = function() { | 494 PropertyDescriptor.prototype.hasSetter = function() { |
| 490 return this.hasSetter_; | 495 return this.hasSetter_; |
| 491 } | 496 } |
| 492 | 497 |
| 493 | 498 |
| 494 // Converts an array returned from Runtime_GetOwnProperty to an actual | 499 // Converts an array returned from Runtime_GetOwnProperty to an actual |
| 495 // property descriptor. For a description of the array layout please | 500 // property descriptor. For a description of the array layout please |
| 496 // see the runtime.cc file. | 501 // see the runtime.cc file. |
| 497 function ConvertDescriptorArrayToDescriptor(desc_array) { | 502 function ConvertDescriptorArrayToDescriptor(desc_array) { |
| 498 if (desc_array == false) { | 503 if (desc_array === false) { |
| 499 throw 'Internal error: invalid desc_array'; | 504 throw 'Internal error: invalid desc_array'; |
| 500 } | 505 } |
| 501 | 506 |
| 502 if (IS_UNDEFINED(desc_array)) { | 507 if (IS_UNDEFINED(desc_array)) { |
| 503 return void 0; | 508 return void 0; |
| 504 } | 509 } |
| 505 | 510 |
| 506 var desc = new PropertyDescriptor(); | 511 var desc = new PropertyDescriptor(); |
| 507 // This is an accessor. | 512 // This is an accessor. |
| 508 if (desc_array[IS_ACCESSOR_INDEX]) { | 513 if (desc_array[IS_ACCESSOR_INDEX]) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 if (props == false) return void 0; | 552 if (props == false) return void 0; |
| 548 | 553 |
| 549 return ConvertDescriptorArrayToDescriptor(props); | 554 return ConvertDescriptorArrayToDescriptor(props); |
| 550 } | 555 } |
| 551 | 556 |
| 552 | 557 |
| 553 // ES5 8.12.9. | 558 // ES5 8.12.9. |
| 554 function DefineOwnProperty(obj, p, desc, should_throw) { | 559 function DefineOwnProperty(obj, p, desc, should_throw) { |
| 555 var current_or_access = %GetOwnProperty(ToObject(obj), ToString(p)); | 560 var current_or_access = %GetOwnProperty(ToObject(obj), ToString(p)); |
| 556 // A false value here means that access checks failed. | 561 // A false value here means that access checks failed. |
| 557 if (current_or_access == false) return void 0; | 562 if (current_or_access === false) return void 0; |
| 558 | 563 |
| 559 var current = ConvertDescriptorArrayToDescriptor(current_or_access); | 564 var current = ConvertDescriptorArrayToDescriptor(current_or_access); |
| 560 var extensible = %IsExtensible(ToObject(obj)); | 565 var extensible = %IsExtensible(ToObject(obj)); |
| 561 | 566 |
| 562 // Error handling according to spec. | 567 // Error handling according to spec. |
| 563 // Step 3 | 568 // Step 3 |
| 564 if (IS_UNDEFINED(current) && !extensible) | 569 if (IS_UNDEFINED(current) && !extensible) |
| 565 throw MakeTypeError("define_disallowed", ["defineProperty"]); | 570 throw MakeTypeError("define_disallowed", ["defineProperty"]); |
| 566 | 571 |
| 567 if (!IS_UNDEFINED(current)) { | 572 if (!IS_UNDEFINED(current)) { |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1243 // ---------------------------------------------------------------------------- | 1248 // ---------------------------------------------------------------------------- |
| 1244 | 1249 |
| 1245 function SetupFunction() { | 1250 function SetupFunction() { |
| 1246 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1251 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1247 "bind", FunctionBind, | 1252 "bind", FunctionBind, |
| 1248 "toString", FunctionToString | 1253 "toString", FunctionToString |
| 1249 )); | 1254 )); |
| 1250 } | 1255 } |
| 1251 | 1256 |
| 1252 SetupFunction(); | 1257 SetupFunction(); |
| OLD | NEW |