| OLD | NEW |
| 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 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
| 8 | 8 |
| 9 // ---------------------------------------------------------------------------- | 9 // ---------------------------------------------------------------------------- |
| 10 // Imports | 10 // Imports |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 return %IsPropertyEnumerable(TO_OBJECT(this), P); | 211 return %IsPropertyEnumerable(TO_OBJECT(this), P); |
| 212 } | 212 } |
| 213 | 213 |
| 214 | 214 |
| 215 // Extensions for providing property getters and setters. | 215 // Extensions for providing property getters and setters. |
| 216 function ObjectDefineGetter(name, fun) { | 216 function ObjectDefineGetter(name, fun) { |
| 217 var receiver = this; | 217 var receiver = this; |
| 218 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { | 218 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { |
| 219 receiver = %GlobalProxy(ObjectDefineGetter); | 219 receiver = %GlobalProxy(ObjectDefineGetter); |
| 220 } | 220 } |
| 221 if (!IS_SPEC_FUNCTION(fun)) { | 221 if (!IS_CALLABLE(fun)) { |
| 222 throw MakeTypeError(kObjectGetterExpectingFunction); | 222 throw MakeTypeError(kObjectGetterExpectingFunction); |
| 223 } | 223 } |
| 224 var desc = new PropertyDescriptor(); | 224 var desc = new PropertyDescriptor(); |
| 225 desc.setGet(fun); | 225 desc.setGet(fun); |
| 226 desc.setEnumerable(true); | 226 desc.setEnumerable(true); |
| 227 desc.setConfigurable(true); | 227 desc.setConfigurable(true); |
| 228 DefineOwnProperty(TO_OBJECT(receiver), $toName(name), desc, false); | 228 DefineOwnProperty(TO_OBJECT(receiver), $toName(name), desc, false); |
| 229 } | 229 } |
| 230 | 230 |
| 231 | 231 |
| 232 function ObjectLookupGetter(name) { | 232 function ObjectLookupGetter(name) { |
| 233 var receiver = this; | 233 var receiver = this; |
| 234 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { | 234 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { |
| 235 receiver = %GlobalProxy(ObjectLookupGetter); | 235 receiver = %GlobalProxy(ObjectLookupGetter); |
| 236 } | 236 } |
| 237 return %LookupAccessor(TO_OBJECT(receiver), $toName(name), GETTER); | 237 return %LookupAccessor(TO_OBJECT(receiver), $toName(name), GETTER); |
| 238 } | 238 } |
| 239 | 239 |
| 240 | 240 |
| 241 function ObjectDefineSetter(name, fun) { | 241 function ObjectDefineSetter(name, fun) { |
| 242 var receiver = this; | 242 var receiver = this; |
| 243 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { | 243 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { |
| 244 receiver = %GlobalProxy(ObjectDefineSetter); | 244 receiver = %GlobalProxy(ObjectDefineSetter); |
| 245 } | 245 } |
| 246 if (!IS_SPEC_FUNCTION(fun)) { | 246 if (!IS_CALLABLE(fun)) { |
| 247 throw MakeTypeError(kObjectSetterExpectingFunction); | 247 throw MakeTypeError(kObjectSetterExpectingFunction); |
| 248 } | 248 } |
| 249 var desc = new PropertyDescriptor(); | 249 var desc = new PropertyDescriptor(); |
| 250 desc.setSet(fun); | 250 desc.setSet(fun); |
| 251 desc.setEnumerable(true); | 251 desc.setEnumerable(true); |
| 252 desc.setConfigurable(true); | 252 desc.setConfigurable(true); |
| 253 DefineOwnProperty(TO_OBJECT(receiver), $toName(name), desc, false); | 253 DefineOwnProperty(TO_OBJECT(receiver), $toName(name), desc, false); |
| 254 } | 254 } |
| 255 | 255 |
| 256 | 256 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 if ("value" in obj) { | 362 if ("value" in obj) { |
| 363 desc.setValue(obj.value); | 363 desc.setValue(obj.value); |
| 364 } | 364 } |
| 365 | 365 |
| 366 if ("writable" in obj) { | 366 if ("writable" in obj) { |
| 367 desc.setWritable(ToBoolean(obj.writable)); | 367 desc.setWritable(ToBoolean(obj.writable)); |
| 368 } | 368 } |
| 369 | 369 |
| 370 if ("get" in obj) { | 370 if ("get" in obj) { |
| 371 var get = obj.get; | 371 var get = obj.get; |
| 372 if (!IS_UNDEFINED(get) && !IS_SPEC_FUNCTION(get)) { | 372 if (!IS_UNDEFINED(get) && !IS_CALLABLE(get)) { |
| 373 throw MakeTypeError(kObjectGetterCallable, get); | 373 throw MakeTypeError(kObjectGetterCallable, get); |
| 374 } | 374 } |
| 375 desc.setGet(get); | 375 desc.setGet(get); |
| 376 } | 376 } |
| 377 | 377 |
| 378 if ("set" in obj) { | 378 if ("set" in obj) { |
| 379 var set = obj.set; | 379 var set = obj.set; |
| 380 if (!IS_UNDEFINED(set) && !IS_SPEC_FUNCTION(set)) { | 380 if (!IS_UNDEFINED(set) && !IS_CALLABLE(set)) { |
| 381 throw MakeTypeError(kObjectSetterCallable, set); | 381 throw MakeTypeError(kObjectSetterCallable, set); |
| 382 } | 382 } |
| 383 desc.setSet(set); | 383 desc.setSet(set); |
| 384 } | 384 } |
| 385 | 385 |
| 386 if (IsInconsistentDescriptor(desc)) { | 386 if (IsInconsistentDescriptor(desc)) { |
| 387 throw MakeTypeError(kValueAndAccessor, obj); | 387 throw MakeTypeError(kValueAndAccessor, obj); |
| 388 } | 388 } |
| 389 return desc; | 389 return desc; |
| 390 } | 390 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 | 530 |
| 531 | 531 |
| 532 // For Harmony proxies. | 532 // For Harmony proxies. |
| 533 function GetTrap(handler, name, defaultTrap) { | 533 function GetTrap(handler, name, defaultTrap) { |
| 534 var trap = handler[name]; | 534 var trap = handler[name]; |
| 535 if (IS_UNDEFINED(trap)) { | 535 if (IS_UNDEFINED(trap)) { |
| 536 if (IS_UNDEFINED(defaultTrap)) { | 536 if (IS_UNDEFINED(defaultTrap)) { |
| 537 throw MakeTypeError(kProxyHandlerTrapMissing, handler, name); | 537 throw MakeTypeError(kProxyHandlerTrapMissing, handler, name); |
| 538 } | 538 } |
| 539 trap = defaultTrap; | 539 trap = defaultTrap; |
| 540 } else if (!IS_SPEC_FUNCTION(trap)) { | 540 } else if (!IS_CALLABLE(trap)) { |
| 541 throw MakeTypeError(kProxyHandlerTrapMustBeCallable, handler, name); | 541 throw MakeTypeError(kProxyHandlerTrapMustBeCallable, handler, name); |
| 542 } | 542 } |
| 543 return trap; | 543 return trap; |
| 544 } | 544 } |
| 545 | 545 |
| 546 | 546 |
| 547 function CallTrap0(handler, name, defaultTrap) { | 547 function CallTrap0(handler, name, defaultTrap) { |
| 548 return %_CallFunction(handler, GetTrap(handler, name, defaultTrap)); | 548 return %_CallFunction(handler, GetTrap(handler, name, defaultTrap)); |
| 549 } | 549 } |
| 550 | 550 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 } else { | 599 } else { |
| 600 return; | 600 return; |
| 601 } | 601 } |
| 602 } | 602 } |
| 603 | 603 |
| 604 | 604 |
| 605 // ES6, draft 12-24-14, section 7.3.8 | 605 // ES6, draft 12-24-14, section 7.3.8 |
| 606 function GetMethod(obj, p) { | 606 function GetMethod(obj, p) { |
| 607 var func = obj[p]; | 607 var func = obj[p]; |
| 608 if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED; | 608 if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED; |
| 609 if (IS_SPEC_FUNCTION(func)) return func; | 609 if (IS_CALLABLE(func)) return func; |
| 610 throw MakeTypeError(kCalledNonCallable, typeof func); | 610 throw MakeTypeError(kCalledNonCallable, typeof func); |
| 611 } | 611 } |
| 612 | 612 |
| 613 | 613 |
| 614 // Harmony proxies. | 614 // Harmony proxies. |
| 615 function DefineProxyProperty(obj, p, attributes, should_throw) { | 615 function DefineProxyProperty(obj, p, attributes, should_throw) { |
| 616 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 616 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
| 617 if (IS_SYMBOL(p)) return false; | 617 if (IS_SYMBOL(p)) return false; |
| 618 | 618 |
| 619 var handler = %GetHandler(obj); | 619 var handler = %GetHandler(obj); |
| (...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 } | 1652 } |
| 1653 | 1653 |
| 1654 | 1654 |
| 1655 function FunctionToString() { | 1655 function FunctionToString() { |
| 1656 return FunctionSourceString(this); | 1656 return FunctionSourceString(this); |
| 1657 } | 1657 } |
| 1658 | 1658 |
| 1659 | 1659 |
| 1660 // ES5 15.3.4.5 | 1660 // ES5 15.3.4.5 |
| 1661 function FunctionBind(this_arg) { // Length is 1. | 1661 function FunctionBind(this_arg) { // Length is 1. |
| 1662 if (!IS_SPEC_FUNCTION(this)) throw MakeTypeError(kFunctionBind); | 1662 if (!IS_CALLABLE(this)) throw MakeTypeError(kFunctionBind); |
| 1663 | 1663 |
| 1664 var boundFunction = function () { | 1664 var boundFunction = function () { |
| 1665 // Poison .arguments and .caller, but is otherwise not detectable. | 1665 // Poison .arguments and .caller, but is otherwise not detectable. |
| 1666 "use strict"; | 1666 "use strict"; |
| 1667 // This function must not use any object literals (Object, Array, RegExp), | 1667 // This function must not use any object literals (Object, Array, RegExp), |
| 1668 // since the literals-array is being used to store the bound data. | 1668 // since the literals-array is being used to store the bound data. |
| 1669 if (%_IsConstructCall()) { | 1669 if (%_IsConstructCall()) { |
| 1670 return %NewObjectFromBound(boundFunction); | 1670 return %NewObjectFromBound(boundFunction); |
| 1671 } | 1671 } |
| 1672 var bindings = %BoundFunctionGetBindings(boundFunction); | 1672 var bindings = %BoundFunctionGetBindings(boundFunction); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1768 | 1768 |
| 1769 // ---------------------------------------------------------------------------- | 1769 // ---------------------------------------------------------------------------- |
| 1770 // Iterator related spec functions. | 1770 // Iterator related spec functions. |
| 1771 | 1771 |
| 1772 // ES6 rev 33, 2015-02-12 | 1772 // ES6 rev 33, 2015-02-12 |
| 1773 // 7.4.1 GetIterator ( obj, method ) | 1773 // 7.4.1 GetIterator ( obj, method ) |
| 1774 function GetIterator(obj, method) { | 1774 function GetIterator(obj, method) { |
| 1775 if (IS_UNDEFINED(method)) { | 1775 if (IS_UNDEFINED(method)) { |
| 1776 method = obj[symbolIterator]; | 1776 method = obj[symbolIterator]; |
| 1777 } | 1777 } |
| 1778 if (!IS_SPEC_FUNCTION(method)) { | 1778 if (!IS_CALLABLE(method)) { |
| 1779 throw MakeTypeError(kNotIterable, obj); | 1779 throw MakeTypeError(kNotIterable, obj); |
| 1780 } | 1780 } |
| 1781 var iterator = %_CallFunction(obj, method); | 1781 var iterator = %_CallFunction(obj, method); |
| 1782 if (!IS_SPEC_OBJECT(iterator)) { | 1782 if (!IS_SPEC_OBJECT(iterator)) { |
| 1783 throw MakeTypeError(kNotAnIterator, iterator); | 1783 throw MakeTypeError(kNotAnIterator, iterator); |
| 1784 } | 1784 } |
| 1785 return iterator; | 1785 return iterator; |
| 1786 } | 1786 } |
| 1787 | 1787 |
| 1788 // ---------------------------------------------------------------------------- | 1788 // ---------------------------------------------------------------------------- |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1810 }); | 1810 }); |
| 1811 | 1811 |
| 1812 %InstallToContext([ | 1812 %InstallToContext([ |
| 1813 "global_eval_fun", GlobalEval, | 1813 "global_eval_fun", GlobalEval, |
| 1814 "object_define_own_property", DefineOwnPropertyFromAPI, | 1814 "object_define_own_property", DefineOwnPropertyFromAPI, |
| 1815 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, | 1815 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, |
| 1816 "to_complete_property_descriptor", ToCompletePropertyDescriptor, | 1816 "to_complete_property_descriptor", ToCompletePropertyDescriptor, |
| 1817 ]); | 1817 ]); |
| 1818 | 1818 |
| 1819 }) | 1819 }) |
| OLD | NEW |