1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This files contains runtime support implemented in JavaScript.
7 // CAUTION: Some of the functions specified in this file are called
8 // directly from compiled code. These are the functions with names in
9 // ALL CAPS. The compiled code passes the first argument in 'this'.
12 // The following declarations are shared with other native JS files.
13 // They are all declared at this one spot to avoid redeclaration errors.
16 var $nonNumberToNumber;
17 var $nonStringToString;
23 var $toPositiveInteger;
27 (function(global, utils) {
29 %CheckIsBootstrapping();
31 var GlobalArray = global.Array;
32 var GlobalBoolean = global.Boolean;
33 var GlobalString = global.String;
34 var GlobalNumber = global.Number;
35 var isConcatSpreadableSymbol =
36 utils.ImportNow("is_concat_spreadable_symbol");
38 // ----------------------------------------------------------------------------
40 /* -----------------------------------
41 - - - C o m p a r i s o n - - -
42 -----------------------------------
45 // ECMA-262 Section 11.9.3.
47 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y);
53 if (IS_NUMBER(y)) return %NumberEquals(x, y);
54 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
55 if (!IS_SPEC_OBJECT(y)) {
56 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal
58 return %NumberEquals(x, %to_number_fun(y));
60 y = %to_primitive(y, NO_HINT);
62 } else if (IS_STRING(x)) {
64 if (IS_STRING(y)) return %StringEquals(x, y);
65 if (IS_NUMBER(y)) return %NumberEquals(%to_number_fun(x), y);
67 return %NumberEquals(%to_number_fun(x), %to_number_fun(y));
69 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
70 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal
71 y = %to_primitive(y, NO_HINT);
73 } else if (IS_SYMBOL(x)) {
74 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1;
75 return 1; // not equal
76 } else if (IS_BOOLEAN(x)) {
77 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1;
78 if (IS_NULL_OR_UNDEFINED(y)) return 1;
79 if (IS_NUMBER(y)) return %NumberEquals(%to_number_fun(x), y);
81 return %NumberEquals(%to_number_fun(x), %to_number_fun(y));
83 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal
85 x = %to_number_fun(x);
86 y = %to_primitive(y, NO_HINT);
87 } else if (IS_NULL_OR_UNDEFINED(x)) {
88 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1;
89 } else if (IS_SIMD_VALUE(x)) {
90 if (!IS_SIMD_VALUE(y)) return 1; // not equal
91 return %SimdEquals(x, y);
94 if (IS_SPEC_OBJECT(y)) return %_ObjectEquals(x, y) ? 0 : 1;
95 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
97 y = %to_number_fun(y);
98 } else if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) {
99 return 1; // not equal
101 x = %to_primitive(x, NO_HINT);
107 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as
108 // the result when either (or both) the operands are NaN.
109 function COMPARE(x, ncr) {
112 // Fast cases for string, numbers and undefined compares.
113 if (IS_STRING(this)) {
114 if (IS_STRING(x)) return %_StringCompare(this, x);
115 if (IS_UNDEFINED(x)) return ncr;
117 } else if (IS_NUMBER(this)) {
118 if (IS_NUMBER(x)) return %NumberCompare(this, x, ncr);
119 if (IS_UNDEFINED(x)) return ncr;
121 } else if (IS_UNDEFINED(this)) {
122 if (!IS_UNDEFINED(x)) {
123 %to_primitive(x, NUMBER_HINT);
126 } else if (IS_UNDEFINED(x)) {
127 %to_primitive(this, NUMBER_HINT);
130 left = %to_primitive(this, NUMBER_HINT);
133 right = %to_primitive(x, NUMBER_HINT);
134 if (IS_STRING(left) && IS_STRING(right)) {
135 return %_StringCompare(left, right);
137 var left_number = %to_number_fun(left);
138 var right_number = %to_number_fun(right);
139 if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr;
140 return %NumberCompare(left_number, right_number, ncr);
144 // Strong mode COMPARE throws if an implicit conversion would be performed
145 function COMPARE_STRONG(x, ncr) {
146 if (IS_STRING(this) && IS_STRING(x)) return %_StringCompare(this, x);
147 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberCompare(this, x, ncr);
149 throw %make_type_error(kStrongImplicitConversion);
154 /* -----------------------------------
155 - - - A r i t h m e t i c - - -
156 -----------------------------------
159 // ECMA-262, section 11.6.1, page 50.
161 // Fast case: Check for number operands and do the addition.
162 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x);
163 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x);
165 // Default implementation.
166 var a = %to_primitive(this, NO_HINT);
167 var b = %to_primitive(x, NO_HINT);
170 return %_StringAdd(a, %to_string_fun(b));
171 } else if (IS_STRING(b)) {
172 return %_StringAdd(%non_string_to_string(a), b);
174 return %NumberAdd(%to_number_fun(a), %to_number_fun(b));
179 // Strong mode ADD throws if an implicit conversion would be performed
180 function ADD_STRONG(x) {
181 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x);
182 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x);
184 throw %make_type_error(kStrongImplicitConversion);
188 // Left operand (this) is already a string.
189 function STRING_ADD_LEFT(y) {
191 if (IS_STRING_WRAPPER(y) && %_IsStringWrapperSafeForDefaultValueOf(y)) {
195 ? %_NumberToString(y)
196 : %to_string_fun(%to_primitive(y, NO_HINT));
199 return %_StringAdd(this, y);
203 // Right operand (y) is already a string.
204 function STRING_ADD_RIGHT(y) {
207 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) {
211 ? %_NumberToString(x)
212 : %to_string_fun(%to_primitive(x, NO_HINT));
215 return %_StringAdd(x, y);
219 // ECMA-262, section 11.6.2, page 50.
221 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
222 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
223 return %NumberSub(x, y);
227 // Strong mode SUB throws if an implicit conversion would be performed
228 function SUB_STRONG(y) {
229 if (IS_NUMBER(this) && IS_NUMBER(y)) {
230 return %NumberSub(this, y);
232 throw %make_type_error(kStrongImplicitConversion);
236 // ECMA-262, section 11.5.1, page 48.
238 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
239 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
240 return %NumberMul(x, y);
244 // Strong mode MUL throws if an implicit conversion would be performed
245 function MUL_STRONG(y) {
246 if (IS_NUMBER(this) && IS_NUMBER(y)) {
247 return %NumberMul(this, y);
249 throw %make_type_error(kStrongImplicitConversion);
253 // ECMA-262, section 11.5.2, page 49.
255 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
256 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
257 return %NumberDiv(x, y);
261 // Strong mode DIV throws if an implicit conversion would be performed
262 function DIV_STRONG(y) {
263 if (IS_NUMBER(this) && IS_NUMBER(y)) {
264 return %NumberDiv(this, y);
266 throw %make_type_error(kStrongImplicitConversion);
270 // ECMA-262, section 11.5.3, page 49.
272 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
273 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
274 return %NumberMod(x, y);
278 // Strong mode MOD throws if an implicit conversion would be performed
279 function MOD_STRONG(y) {
280 if (IS_NUMBER(this) && IS_NUMBER(y)) {
281 return %NumberMod(this, y);
283 throw %make_type_error(kStrongImplicitConversion);
287 /* -------------------------------------------
288 - - - B i t o p e r a t i o n s - - -
289 -------------------------------------------
292 // ECMA-262, section 11.10, page 57.
294 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
295 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
296 return %NumberOr(x, y);
300 // Strong mode BIT_OR throws if an implicit conversion would be performed
301 function BIT_OR_STRONG(y) {
302 if (IS_NUMBER(this) && IS_NUMBER(y)) {
303 return %NumberOr(this, y);
305 throw %make_type_error(kStrongImplicitConversion);
309 // ECMA-262, section 11.10, page 57.
310 function BIT_AND(y) {
312 if (IS_NUMBER(this)) {
314 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
316 x = %non_number_to_number(this);
317 // Make sure to convert the right operand to a number before
318 // bailing out in the fast case, but after converting the
319 // left operand. This ensures that valueOf methods on the right
320 // operand are always executed.
321 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
322 // Optimize for the case where we end up AND'ing a value
323 // that doesn't convert to a number. This is common in
324 // certain benchmarks.
325 if (NUMBER_IS_NAN(x)) return 0;
327 return %NumberAnd(x, y);
331 // Strong mode BIT_AND throws if an implicit conversion would be performed
332 function BIT_AND_STRONG(y) {
333 if (IS_NUMBER(this) && IS_NUMBER(y)) {
334 return %NumberAnd(this, y);
336 throw %make_type_error(kStrongImplicitConversion);
340 // ECMA-262, section 11.10, page 57.
341 function BIT_XOR(y) {
342 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
343 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
344 return %NumberXor(x, y);
348 // Strong mode BIT_XOR throws if an implicit conversion would be performed
349 function BIT_XOR_STRONG(y) {
350 if (IS_NUMBER(this) && IS_NUMBER(y)) {
351 return %NumberXor(this, y);
353 throw %make_type_error(kStrongImplicitConversion);
357 // ECMA-262, section 11.7.1, page 51.
359 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
360 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
361 return %NumberShl(x, y);
365 // Strong mode SHL throws if an implicit conversion would be performed
366 function SHL_STRONG(y) {
367 if (IS_NUMBER(this) && IS_NUMBER(y)) {
368 return %NumberShl(this, y);
370 throw %make_type_error(kStrongImplicitConversion);
374 // ECMA-262, section 11.7.2, page 51.
377 if (IS_NUMBER(this)) {
379 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
381 x = %non_number_to_number(this);
382 // Make sure to convert the right operand to a number before
383 // bailing out in the fast case, but after converting the
384 // left operand. This ensures that valueOf methods on the right
385 // operand are always executed.
386 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
387 // Optimize for the case where we end up shifting a value
388 // that doesn't convert to a number. This is common in
389 // certain benchmarks.
390 if (NUMBER_IS_NAN(x)) return 0;
392 return %NumberSar(x, y);
396 // Strong mode SAR throws if an implicit conversion would be performed
397 function SAR_STRONG(y) {
398 if (IS_NUMBER(this) && IS_NUMBER(y)) {
399 return %NumberSar(this, y);
401 throw %make_type_error(kStrongImplicitConversion);
405 // ECMA-262, section 11.7.3, page 52.
407 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
408 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
409 return %NumberShr(x, y);
413 // Strong mode SHR throws if an implicit conversion would be performed
414 function SHR_STRONG(y) {
415 if (IS_NUMBER(this) && IS_NUMBER(y)) {
416 return %NumberShr(this, y);
418 throw %make_type_error(kStrongImplicitConversion);
422 /* -----------------------------
423 - - - H e l p e r s - - -
424 -----------------------------
427 function CALL_NON_FUNCTION() {
428 var delegate = %GetFunctionDelegate(this);
429 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength());
433 function CALL_NON_FUNCTION_AS_CONSTRUCTOR() {
434 var delegate = %GetConstructorDelegate(this);
435 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength());
439 function CALL_FUNCTION_PROXY() {
440 var arity = %_ArgumentsLength() - 1;
441 var proxy = %_Arguments(arity); // The proxy comes in as an additional arg.
442 var trap = %GetCallTrap(proxy);
443 return %Apply(trap, this, arguments, 0, arity);
447 function CALL_FUNCTION_PROXY_AS_CONSTRUCTOR () {
449 var trap = %GetConstructTrap(proxy);
450 return %Apply(trap, this, arguments, 0, %_ArgumentsLength());
454 function APPLY_PREPARE(args) {
456 // First check whether length is a positive Smi and args is an
457 // array. This is the fast case. If this fails, we do the slow case
458 // that takes care of more eventualities.
459 if (IS_ARRAY(args)) {
460 length = args.length;
461 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength &&
467 length = (args == null) ? 0 : TO_UINT32(args.length);
469 // We can handle any number of apply arguments if the stack is
470 // big enough, but sanity check the value to avoid overflow when
471 // multiplying with pointer size.
472 if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow);
474 if (!IS_CALLABLE(this)) {
475 throw %make_type_error(kApplyNonFunction, %to_string_fun(this),
479 // Make sure the arguments list has the right type.
480 if (args != null && !IS_SPEC_OBJECT(args)) {
481 throw %make_type_error(kWrongArgs, "Function.prototype.apply");
484 // Return the length which is the number of arguments to copy to the
485 // stack. It is guaranteed to be a small integer at this point.
490 function REFLECT_APPLY_PREPARE(args) {
492 // First check whether length is a positive Smi and args is an
493 // array. This is the fast case. If this fails, we do the slow case
494 // that takes care of more eventualities.
495 if (IS_ARRAY(args)) {
496 length = args.length;
497 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength &&
503 if (!IS_CALLABLE(this)) {
504 throw %make_type_error(kCalledNonCallable, %to_string_fun(this));
507 if (!IS_SPEC_OBJECT(args)) {
508 throw %make_type_error(kWrongArgs, "Reflect.apply");
511 length = %to_length_fun(args.length);
513 // We can handle any number of apply arguments if the stack is
514 // big enough, but sanity check the value to avoid overflow when
515 // multiplying with pointer size.
516 if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow);
518 // Return the length which is the number of arguments to copy to the
519 // stack. It is guaranteed to be a small integer at this point.
524 function REFLECT_CONSTRUCT_PREPARE(
527 var ctorOk = IS_CALLABLE(this) && %IsConstructor(this);
528 var newTargetOk = IS_CALLABLE(newTarget) && %IsConstructor(newTarget);
530 // First check whether length is a positive Smi and args is an
531 // array. This is the fast case. If this fails, we do the slow case
532 // that takes care of more eventualities.
533 if (IS_ARRAY(args)) {
534 length = args.length;
535 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength &&
536 ctorOk && newTargetOk) {
542 if (!IS_CALLABLE(this)) {
543 throw %make_type_error(kCalledNonCallable, %to_string_fun(this));
545 throw %make_type_error(kNotConstructor, %to_string_fun(this));
550 if (!IS_CALLABLE(newTarget)) {
551 throw %make_type_error(kCalledNonCallable, %to_string_fun(newTarget));
553 throw %make_type_error(kNotConstructor, %to_string_fun(newTarget));
557 if (!IS_SPEC_OBJECT(args)) {
558 throw %make_type_error(kWrongArgs, "Reflect.construct");
561 length = %to_length_fun(args.length);
563 // We can handle any number of apply arguments if the stack is
564 // big enough, but sanity check the value to avoid overflow when
565 // multiplying with pointer size.
566 if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow);
568 // Return the length which is the number of arguments to copy to the
569 // stack. It is guaranteed to be a small integer at this point.
574 function CONCAT_ITERABLE_TO_ARRAY(iterable) {
575 return %concat_iterable_to_array(this, iterable);
579 function STACK_OVERFLOW(length) {
580 throw %make_range_error(kStackOverflow);
584 /* -------------------------------------
585 - - - C o n v e r s i o n s - - -
586 -------------------------------------
589 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint,
590 // (1) for number hint, and (2) for string hint.
591 function ToPrimitive(x, hint) {
592 if (!IS_SPEC_OBJECT(x)) return x;
593 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT;
594 return (hint == NUMBER_HINT) ? DefaultNumber(x) : DefaultString(x);
598 // ECMA-262, section 9.2, page 30
599 function ToBoolean(x) {
600 if (IS_BOOLEAN(x)) return x;
601 if (IS_STRING(x)) return x.length != 0;
602 if (x == null) return false;
603 if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x));
608 // ECMA-262, section 9.3, page 31.
609 function ToNumber(x) {
610 if (IS_NUMBER(x)) return x;
612 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x)
613 : %StringToNumber(x);
615 if (IS_BOOLEAN(x)) return x ? 1 : 0;
616 if (IS_UNDEFINED(x)) return NAN;
617 // Types that can't be converted to number are caught in DefaultNumber.
618 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x));
621 function NonNumberToNumber(x) {
623 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x)
624 : %StringToNumber(x);
626 if (IS_BOOLEAN(x)) return x ? 1 : 0;
627 if (IS_UNDEFINED(x)) return NAN;
628 // Types that can't be converted to number are caught in DefaultNumber.
629 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x));
633 // ECMA-262, section 9.8, page 35.
634 function ToString(x) {
635 if (IS_STRING(x)) return x;
636 if (IS_NUMBER(x)) return %_NumberToString(x);
637 if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
638 if (IS_UNDEFINED(x)) return 'undefined';
639 // Types that can't be converted to string are caught in DefaultString.
640 return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x));
643 function NonStringToString(x) {
644 if (IS_NUMBER(x)) return %_NumberToString(x);
645 if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
646 if (IS_UNDEFINED(x)) return 'undefined';
647 // Types that can't be converted to string are caught in DefaultString.
648 return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x));
652 // ECMA-262, section 9.4, page 34.
653 function ToInteger(x) {
654 if (%_IsSmi(x)) return x;
655 return %NumberToInteger(ToNumber(x));
659 // ES6, draft 08-24-14, section 7.1.15
660 function ToLength(arg) {
661 arg = ToInteger(arg);
662 if (arg < 0) return 0;
663 return arg < GlobalNumber.MAX_SAFE_INTEGER ? arg
664 : GlobalNumber.MAX_SAFE_INTEGER;
669 function SameValue(x, y) {
670 if (typeof x != typeof y) return false;
672 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true;
673 // x is +0 and y is -0 or vice versa.
674 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) {
678 if (IS_SIMD_VALUE(x)) return %SimdSameValue(x, y);
683 // ES6, section 7.2.4
684 function SameValueZero(x, y) {
685 if (typeof x != typeof y) return false;
687 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true;
689 if (IS_SIMD_VALUE(x)) return %SimdSameValueZero(x, y);
694 function ConcatIterableToArray(target, iterable) {
695 var index = target.length;
696 for (var element of iterable) {
697 %AddElement(target, index++, element);
703 /* ---------------------------------
704 - - - U t i l i t i e s - - -
705 ---------------------------------
708 // Returns if the given x is a primitive value - not an object or a
710 function IsPrimitive(x) {
711 // Even though the type of null is "object", null is still
712 // considered a primitive value. IS_SPEC_OBJECT handles this correctly
713 // (i.e., it will return false if x is null).
714 return !IS_SPEC_OBJECT(x);
718 // ES6, draft 10-14-14, section 22.1.3.1.1
719 function IsConcatSpreadable(O) {
720 if (!IS_SPEC_OBJECT(O)) return false;
721 var spreadable = O[isConcatSpreadableSymbol];
722 if (IS_UNDEFINED(spreadable)) return IS_ARRAY(O);
723 return ToBoolean(spreadable);
727 // ECMA-262, section 8.6.2.6, page 28.
728 function DefaultNumber(x) {
729 var valueOf = x.valueOf;
730 if (IS_CALLABLE(valueOf)) {
731 var v = %_CallFunction(x, valueOf);
732 if (IS_SYMBOL(v)) throw MakeTypeError(kSymbolToNumber);
733 if (IS_SIMD_VALUE(x)) throw MakeTypeError(kSimdToNumber);
734 if (IsPrimitive(v)) return v;
736 var toString = x.toString;
737 if (IS_CALLABLE(toString)) {
738 var s = %_CallFunction(x, toString);
739 if (IsPrimitive(s)) return s;
741 throw MakeTypeError(kCannotConvertToPrimitive);
744 // ECMA-262, section 8.6.2.6, page 28.
745 function DefaultString(x) {
746 if (!IS_SYMBOL_WRAPPER(x)) {
747 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToString);
748 var toString = x.toString;
749 if (IS_CALLABLE(toString)) {
750 var s = %_CallFunction(x, toString);
751 if (IsPrimitive(s)) return s;
754 var valueOf = x.valueOf;
755 if (IS_CALLABLE(valueOf)) {
756 var v = %_CallFunction(x, valueOf);
757 if (IsPrimitive(v)) return v;
760 throw MakeTypeError(kCannotConvertToPrimitive);
763 function ToPositiveInteger(x, rangeErrorIndex) {
764 var i = TO_INTEGER_MAP_MINUS_ZERO(x);
765 if (i < 0) throw MakeRangeError(rangeErrorIndex);
769 //----------------------------------------------------------------------------
771 // NOTE: Setting the prototype for Array must take place as early as
772 // possible due to code generation for array literals. When
773 // generating code for a array literal a boilerplate array is created
774 // that is cloned when running the code. It is essential that the
775 // boilerplate gets the right prototype.
776 %FunctionSetPrototype(GlobalArray, new GlobalArray(0));
778 // ----------------------------------------------------------------------------
781 $defaultString = DefaultString;
782 $NaN = %GetRootNaN();
783 $nonNumberToNumber = NonNumberToNumber;
784 $nonStringToString = NonStringToString;
785 $sameValue = SameValue;
786 $sameValueZero = SameValueZero;
787 $toInteger = ToInteger;
788 $toLength = ToLength;
789 $toNumber = ToNumber;
790 $toPositiveInteger = ToPositiveInteger;
791 $toPrimitive = ToPrimitive;
792 $toString = ToString;
796 "add_strong_builtin", ADD_STRONG,
797 "apply_prepare_builtin", APPLY_PREPARE,
798 "bit_and_builtin", BIT_AND,
799 "bit_and_strong_builtin", BIT_AND_STRONG,
800 "bit_or_builtin", BIT_OR,
801 "bit_or_strong_builtin", BIT_OR_STRONG,
802 "bit_xor_builtin", BIT_XOR,
803 "bit_xor_strong_builtin", BIT_XOR_STRONG,
804 "call_function_proxy_as_constructor_builtin", CALL_FUNCTION_PROXY_AS_CONSTRUCTOR,
805 "call_function_proxy_builtin", CALL_FUNCTION_PROXY,
806 "call_non_function_as_constructor_builtin", CALL_NON_FUNCTION_AS_CONSTRUCTOR,
807 "call_non_function_builtin", CALL_NON_FUNCTION,
808 "compare_builtin", COMPARE,
809 "compare_strong_builtin", COMPARE_STRONG,
810 "concat_iterable_to_array_builtin", CONCAT_ITERABLE_TO_ARRAY,
812 "div_strong_builtin", DIV_STRONG,
813 "equals_builtin", EQUALS,
815 "mod_strong_builtin", MOD_STRONG,
817 "mul_strong_builtin", MUL_STRONG,
818 "reflect_apply_prepare_builtin", REFLECT_APPLY_PREPARE,
819 "reflect_construct_prepare_builtin", REFLECT_CONSTRUCT_PREPARE,
821 "sar_strong_builtin", SAR_STRONG,
823 "shl_strong_builtin", SHL_STRONG,
825 "shr_strong_builtin", SHR_STRONG,
826 "stack_overflow_builtin", STACK_OVERFLOW,
827 "string_add_left_builtin", STRING_ADD_LEFT,
828 "string_add_right_builtin", STRING_ADD_RIGHT,
830 "sub_strong_builtin", SUB_STRONG,
834 "concat_iterable_to_array", ConcatIterableToArray,
835 "non_number_to_number", NonNumberToNumber,
836 "non_string_to_string", NonStringToString,
837 "to_integer_fun", ToInteger,
838 "to_length_fun", ToLength,
839 "to_number_fun", ToNumber,
840 "to_primitive", ToPrimitive,
841 "to_string_fun", ToString,
844 utils.Export(function(to) {
845 to.ToBoolean = ToBoolean;
846 to.ToLength = ToLength;
847 to.ToNumber = ToNumber;
848 to.ToPrimitive = ToPrimitive;
849 to.ToString = ToString;