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