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 var desc = new PropertyDescriptor(); | 254 return %DefineAccessor(ToObject(this), ToString(name), GETTER, fun); |
255 desc.setGet(fun); | |
256 desc.setEnumerable(true); | |
257 desc.setConfigurable(true); | |
258 DefineOwnProperty(ToObject(this), ToString(name), desc, true); | |
259 } | 255 } |
260 | 256 |
261 | 257 |
262 function ObjectLookupGetter(name) { | 258 function ObjectLookupGetter(name) { |
263 if (this == null && !IS_UNDETECTABLE(this)) { | 259 if (this == null && !IS_UNDETECTABLE(this)) { |
264 throw new $TypeError('Object.prototype.__lookupGetter__: this is Null'); | 260 throw new $TypeError('Object.prototype.__lookupGetter__: this is Null'); |
265 } | 261 } |
266 return %LookupAccessor(ToObject(this), ToString(name), GETTER); | 262 return %LookupAccessor(ToObject(this), ToString(name), GETTER); |
267 } | 263 } |
268 | 264 |
269 | 265 |
270 function ObjectDefineSetter(name, fun) { | 266 function ObjectDefineSetter(name, fun) { |
271 if (this == null && !IS_UNDETECTABLE(this)) { | 267 if (this == null && !IS_UNDETECTABLE(this)) { |
272 throw new $TypeError('Object.prototype.__defineSetter__: this is Null'); | 268 throw new $TypeError('Object.prototype.__defineSetter__: this is Null'); |
273 } | 269 } |
274 if (!IS_FUNCTION(fun)) { | 270 if (!IS_FUNCTION(fun)) { |
275 throw new $TypeError( | 271 throw new $TypeError( |
276 'Object.prototype.__defineSetter__: Expecting function'); | 272 'Object.prototype.__defineSetter__: Expecting function'); |
277 } | 273 } |
278 var desc = new PropertyDescriptor(); | 274 return %DefineAccessor(ToObject(this), ToString(name), SETTER, fun); |
279 desc.setSet(fun); | |
280 desc.setEnumerable(true); | |
281 desc.setConfigurable(true); | |
282 DefineOwnProperty(ToObject(this), ToString(name), desc, true); | |
283 } | 275 } |
284 | 276 |
285 | 277 |
286 function ObjectLookupSetter(name) { | 278 function ObjectLookupSetter(name) { |
287 if (this == null && !IS_UNDETECTABLE(this)) { | 279 if (this == null && !IS_UNDETECTABLE(this)) { |
288 throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); | 280 throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); |
289 } | 281 } |
290 return %LookupAccessor(ToObject(this), ToString(name), SETTER); | 282 return %LookupAccessor(ToObject(this), ToString(name), SETTER); |
291 } | 283 } |
292 | 284 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 this.enumerable_ = false; | 387 this.enumerable_ = false; |
396 this.hasEnumerable_ = false; | 388 this.hasEnumerable_ = false; |
397 this.configurable_ = false; | 389 this.configurable_ = false; |
398 this.hasConfigurable_ = false; | 390 this.hasConfigurable_ = false; |
399 this.get_ = void 0; | 391 this.get_ = void 0; |
400 this.hasGetter_ = false; | 392 this.hasGetter_ = false; |
401 this.set_ = void 0; | 393 this.set_ = void 0; |
402 this.hasSetter_ = false; | 394 this.hasSetter_ = false; |
403 } | 395 } |
404 | 396 |
405 PropertyDescriptor.prototype.__proto__ = null; | |
406 PropertyDescriptor.prototype.toString = function() { | |
407 return "[object PropertyDescriptor]"; | |
408 }; | |
409 | 397 |
410 PropertyDescriptor.prototype.setValue = function(value) { | 398 PropertyDescriptor.prototype.setValue = function(value) { |
411 this.value_ = value; | 399 this.value_ = value; |
412 this.hasValue_ = true; | 400 this.hasValue_ = true; |
413 } | 401 } |
414 | 402 |
415 | 403 |
416 PropertyDescriptor.prototype.getValue = function() { | 404 PropertyDescriptor.prototype.getValue = function() { |
417 return this.value_; | 405 return this.value_; |
418 } | 406 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 | 488 |
501 PropertyDescriptor.prototype.hasSetter = function() { | 489 PropertyDescriptor.prototype.hasSetter = function() { |
502 return this.hasSetter_; | 490 return this.hasSetter_; |
503 } | 491 } |
504 | 492 |
505 | 493 |
506 // Converts an array returned from Runtime_GetOwnProperty to an actual | 494 // Converts an array returned from Runtime_GetOwnProperty to an actual |
507 // property descriptor. For a description of the array layout please | 495 // property descriptor. For a description of the array layout please |
508 // see the runtime.cc file. | 496 // see the runtime.cc file. |
509 function ConvertDescriptorArrayToDescriptor(desc_array) { | 497 function ConvertDescriptorArrayToDescriptor(desc_array) { |
510 if (desc_array === false) { | 498 if (desc_array == false) { |
511 throw 'Internal error: invalid desc_array'; | 499 throw 'Internal error: invalid desc_array'; |
512 } | 500 } |
513 | 501 |
514 if (IS_UNDEFINED(desc_array)) { | 502 if (IS_UNDEFINED(desc_array)) { |
515 return void 0; | 503 return void 0; |
516 } | 504 } |
517 | 505 |
518 var desc = new PropertyDescriptor(); | 506 var desc = new PropertyDescriptor(); |
519 // This is an accessor. | 507 // This is an accessor. |
520 if (desc_array[IS_ACCESSOR_INDEX]) { | 508 if (desc_array[IS_ACCESSOR_INDEX]) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 if (props == false) return void 0; | 547 if (props == false) return void 0; |
560 | 548 |
561 return ConvertDescriptorArrayToDescriptor(props); | 549 return ConvertDescriptorArrayToDescriptor(props); |
562 } | 550 } |
563 | 551 |
564 | 552 |
565 // ES5 8.12.9. | 553 // ES5 8.12.9. |
566 function DefineOwnProperty(obj, p, desc, should_throw) { | 554 function DefineOwnProperty(obj, p, desc, should_throw) { |
567 var current_or_access = %GetOwnProperty(ToObject(obj), ToString(p)); | 555 var current_or_access = %GetOwnProperty(ToObject(obj), ToString(p)); |
568 // A false value here means that access checks failed. | 556 // A false value here means that access checks failed. |
569 if (current_or_access === false) return void 0; | 557 if (current_or_access == false) return void 0; |
570 | 558 |
571 var current = ConvertDescriptorArrayToDescriptor(current_or_access); | 559 var current = ConvertDescriptorArrayToDescriptor(current_or_access); |
572 var extensible = %IsExtensible(ToObject(obj)); | 560 var extensible = %IsExtensible(ToObject(obj)); |
573 | 561 |
574 // Error handling according to spec. | 562 // Error handling according to spec. |
575 // Step 3 | 563 // Step 3 |
576 if (IS_UNDEFINED(current) && !extensible) | 564 if (IS_UNDEFINED(current) && !extensible) |
577 throw MakeTypeError("define_disallowed", ["defineProperty"]); | 565 throw MakeTypeError("define_disallowed", ["defineProperty"]); |
578 | 566 |
579 if (!IS_UNDEFINED(current)) { | 567 if (!IS_UNDEFINED(current)) { |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 // ---------------------------------------------------------------------------- | 1243 // ---------------------------------------------------------------------------- |
1256 | 1244 |
1257 function SetupFunction() { | 1245 function SetupFunction() { |
1258 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1246 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1259 "bind", FunctionBind, | 1247 "bind", FunctionBind, |
1260 "toString", FunctionToString | 1248 "toString", FunctionToString |
1261 )); | 1249 )); |
1262 } | 1250 } |
1263 | 1251 |
1264 SetupFunction(); | 1252 SetupFunction(); |
OLD | NEW |