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' and
10 // it does not push the function onto the stack. This means that you
11 // cannot use contexts in all these functions.
14 /* -----------------------------------
15 - - - C o m p a r i s o n - - -
16 -----------------------------------
19 // The following declarations are shared with other native JS files.
20 // They are all declared at this one spot to avoid redeclaration errors.
21 var $Object = global.Object;
22 var $Array = global.Array;
23 var $String = global.String;
24 var $Number = global.Number;
25 var $Function = global.Function;
26 var $Boolean = global.Boolean;
27 var $NaN = %GetRootNaN();
29 // ECMA-262 Section 11.9.3.
31 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y);
37 if (IS_NUMBER(y)) return %NumberEquals(x, y);
38 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
39 if (!IS_SPEC_OBJECT(y)) {
41 return %NumberEquals(x, %ToNumber(y));
43 y = %ToPrimitive(y, NO_HINT);
45 } else if (IS_STRING(x)) {
47 if (IS_STRING(y)) return %StringEquals(x, y);
48 if (IS_SYMBOL(y)) return 1; // not equal
49 if (IS_NUMBER(y)) return %NumberEquals(%ToNumber(x), y);
50 if (IS_BOOLEAN(y)) return %NumberEquals(%ToNumber(x), %ToNumber(y));
51 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
52 if (IsFloat32x4(y) || IsFloat64x2(y) || IsInt32x4(y)) {
53 return %StringEquals(x, %ToString(y));
55 y = %ToPrimitive(y, NO_HINT);
57 } else if (IS_SYMBOL(x)) {
58 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1;
59 return 1; // not equal
60 } else if (IsFloat32x4(x)) {
62 if (IsFloat32x4(y) || IsInt32x4(y)) {
63 return (x.x == y.x && x.y == y.y && x.z == y.z && x.w == y.w) ? 0 : 1;
65 if (IS_STRING(y)) return %StringEquals(%ToString(x), y);
66 if (IS_NUMBER(y)) return 1; // not equal
67 if (IS_SYMBOL(y)) return 1; // not equal
68 if (IS_BOOLEAN(y)) return y ? 0 : 1;
69 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
70 y = %ToPrimitive(y, NO_HINT);
72 } else if (IsFloat64x2(x)) {
75 return (x.x == y.x && x.y == y.y) ? 0 : 1;
77 if (IS_STRING(y)) return %StringEquals(%ToString(x), y);
78 if (IS_NUMBER(y)) return 1; // not equal
79 if (IS_SYMBOL(y)) return 1; // not equal
80 if (IS_BOOLEAN(y)) return y ? 0 : 1;
81 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
82 y = %ToPrimitive(y, NO_HINT);
84 } else if (IsInt32x4(x)) {
86 if (IsFloat32x4(y) || IsInt32x4(y)) {
87 return (x.x == y.x && x.y == y.y && x.z == y.z && x.w == y.w) ? 0 : 1;
89 if (IS_STRING(y)) return %StringEquals(%ToString(x), y);
90 if (IS_NUMBER(y)) return 1; // not equal
91 if (IS_SYMBOL(y)) return 1; // not equal
92 if (IS_BOOLEAN(y)) return y ? 0 : 1;
93 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
94 y = %ToPrimitive(y, NO_HINT);
96 } else if (IS_BOOLEAN(x)) {
97 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1;
98 if (IS_NULL_OR_UNDEFINED(y)) return 1;
99 if (IS_NUMBER(y)) return %NumberEquals(%ToNumber(x), y);
100 if (IS_STRING(y)) return %NumberEquals(%ToNumber(x), %ToNumber(y));
101 if (IS_SYMBOL(y)) return 1; // not equal
102 if (IsFloat32x4(y) || IsFloat64x2(y) || IsInt32x4(y)) return x ? 0 : 1;
105 y = %ToPrimitive(y, NO_HINT);
106 } else if (IS_NULL_OR_UNDEFINED(x)) {
107 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1;
110 if (IS_SPEC_OBJECT(y)) {
111 return %_ObjectEquals(x, y) ? 0 : 1;
113 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
114 if (IS_SYMBOL(y)) return 1; // not equal
115 if (IS_BOOLEAN(y)) y = %ToNumber(y);
116 x = %ToPrimitive(x, NO_HINT);
121 // ECMA-262, section 11.9.4, page 56.
122 function STRICT_EQUALS(x) {
123 if (IS_STRING(this)) {
124 if (!IS_STRING(x)) return 1; // not equal
125 return %StringEquals(this, x);
128 if (IS_NUMBER(this)) {
129 if (!IS_NUMBER(x)) return 1; // not equal
130 return %NumberEquals(this, x);
133 if (IsFloat32x4(this)) {
134 if (!IsFloat32x4(x)) return 1; // not equal
135 return (this.x == x.x && this.y == x.y &&
136 this.z == x.z && this.w == x.w) ? 0 : 1;
139 if (IsFloat64x2(this)) {
140 if (!IsFloat64x2(x)) return 1; // not equal
141 return (this.x == x.x && this.y == x.y) ? 0 : 1;
144 if (IsInt32x4(this)) {
145 if (!IsInt32x4(x)) return 1; // not equal
146 return (this.x == x.x && this.y == x.y &&
147 this.z == x.z && this.w == x.w) ? 0 : 1;
150 // If anything else gets here, we just do simple identity check.
151 // Objects (including functions), null, undefined and booleans were
152 // checked in the CompareStub, so there should be nothing left.
153 return %_ObjectEquals(this, x) ? 0 : 1;
157 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as
158 // the result when either (or both) the operands are NaN.
159 function COMPARE(x, ncr) {
162 // Fast cases for string, numbers and undefined compares.
163 if (IS_STRING(this)) {
164 if (IS_STRING(x)) return %_StringCompare(this, x);
165 if (IS_UNDEFINED(x)) return ncr;
167 } else if (IS_NUMBER(this)) {
168 if (IS_NUMBER(x)) return %NumberCompare(this, x, ncr);
169 if (IS_UNDEFINED(x)) return ncr;
171 } else if (IS_UNDEFINED(this)) {
172 if (!IS_UNDEFINED(x)) {
173 %ToPrimitive(x, NUMBER_HINT);
176 } else if (IS_UNDEFINED(x)) {
177 %ToPrimitive(this, NUMBER_HINT);
180 left = %ToPrimitive(this, NUMBER_HINT);
183 right = %ToPrimitive(x, NUMBER_HINT);
184 if (IS_STRING(left) && IS_STRING(right)) {
185 return %_StringCompare(left, right);
186 } else if ((IsFloat32x4(left) || IsInt32x4(left)) &&
187 (IsFloat32x4(right) || IsInt32x4(right))) {
188 if ((left.x == right.x) && (left.y == right.y) &&
189 (left.z == right.z) && (left.w == right.w)) {
192 if ((left.x < right.x) && (left.y < right.y) &&
193 (left.z < right.z) && (left.w < right.w)) {
196 if ((left.x > right.x) && (left.y > right.y) &&
197 (left.z > right.z) && (left.w > right.w)) {
200 } else if (IsFloat64x2(left) && IsFloat64x2(right)) {
201 if ((left.x == right.x) && (left.y == right.y)) {
204 if ((left.x < right.x) && (left.y < right.y)) {
207 if ((left.x > right.x) && (left.y > right.y)) {
211 var left_number = %ToNumber(left);
212 var right_number = %ToNumber(right);
213 if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr;
214 return %NumberCompare(left_number, right_number, ncr);
220 /* -----------------------------------
221 - - - A r i t h m e t i c - - -
222 -----------------------------------
225 // ECMA-262, section 11.6.1, page 50.
227 // Fast case: Check for number operands and do the addition.
228 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x);
229 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x);
231 // Default implementation.
232 var a = %ToPrimitive(this, NO_HINT);
233 var b = %ToPrimitive(x, NO_HINT);
236 return %_StringAdd(a, %ToString(b));
237 } else if (IS_STRING(b)) {
238 return %_StringAdd(%NonStringToString(a), b);
240 return %NumberAdd(%ToNumber(a), %ToNumber(b));
245 // Left operand (this) is already a string.
246 function STRING_ADD_LEFT(y) {
248 if (IS_STRING_WRAPPER(y) && %_IsStringWrapperSafeForDefaultValueOf(y)) {
252 ? %_NumberToString(y)
253 : %ToString(%ToPrimitive(y, NO_HINT));
256 return %_StringAdd(this, y);
260 // Right operand (y) is already a string.
261 function STRING_ADD_RIGHT(y) {
264 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) {
268 ? %_NumberToString(x)
269 : %ToString(%ToPrimitive(x, NO_HINT));
272 return %_StringAdd(x, y);
276 // ECMA-262, section 11.6.2, page 50.
278 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this);
279 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y);
280 return %NumberSub(x, y);
284 // ECMA-262, section 11.5.1, page 48.
286 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this);
287 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y);
288 return %NumberMul(x, y);
292 // ECMA-262, section 11.5.2, page 49.
294 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this);
295 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y);
296 return %NumberDiv(x, y);
300 // ECMA-262, section 11.5.3, page 49.
302 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this);
303 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y);
304 return %NumberMod(x, y);
309 /* -------------------------------------------
310 - - - B i t o p e r a t i o n s - - -
311 -------------------------------------------
314 // ECMA-262, section 11.10, page 57.
316 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this);
317 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y);
318 return %NumberOr(x, y);
322 // ECMA-262, section 11.10, page 57.
323 function BIT_AND(y) {
325 if (IS_NUMBER(this)) {
327 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y);
329 x = %NonNumberToNumber(this);
330 // Make sure to convert the right operand to a number before
331 // bailing out in the fast case, but after converting the
332 // left operand. This ensures that valueOf methods on the right
333 // operand are always executed.
334 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y);
335 // Optimize for the case where we end up AND'ing a value
336 // that doesn't convert to a number. This is common in
337 // certain benchmarks.
338 if (NUMBER_IS_NAN(x)) return 0;
340 return %NumberAnd(x, y);
344 // ECMA-262, section 11.10, page 57.
345 function BIT_XOR(y) {
346 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this);
347 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y);
348 return %NumberXor(x, y);
352 // ECMA-262, section 11.7.1, page 51.
354 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this);
355 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y);
356 return %NumberShl(x, y);
360 // ECMA-262, section 11.7.2, page 51.
363 if (IS_NUMBER(this)) {
365 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y);
367 x = %NonNumberToNumber(this);
368 // Make sure to convert the right operand to a number before
369 // bailing out in the fast case, but after converting the
370 // left operand. This ensures that valueOf methods on the right
371 // operand are always executed.
372 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y);
373 // Optimize for the case where we end up shifting a value
374 // that doesn't convert to a number. This is common in
375 // certain benchmarks.
376 if (NUMBER_IS_NAN(x)) return 0;
378 return %NumberSar(x, y);
382 // ECMA-262, section 11.7.3, page 52.
384 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this);
385 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y);
386 return %NumberShr(x, y);
391 /* -----------------------------
392 - - - H e l p e r s - - -
393 -----------------------------
396 // ECMA-262, section 11.4.1, page 46.
397 function DELETE(key, strict) {
398 return %DeleteProperty(%ToObject(this), %ToName(key), strict);
402 // ECMA-262, section 11.8.7, page 54.
404 if (!IS_SPEC_OBJECT(x)) {
405 throw %MakeTypeError('invalid_in_operator_use', [this, x]);
407 return %_IsNonNegativeSmi(this) ?
408 %HasElement(x, this) : %HasProperty(x, %ToName(this));
412 // ECMA-262, section 11.8.6, page 54. To make the implementation more
413 // efficient, the return value should be zero if the 'this' is an
414 // instance of F, and non-zero if not. This makes it possible to avoid
415 // an expensive ToBoolean conversion in the generated code.
416 function INSTANCE_OF(F) {
418 if (!IS_SPEC_FUNCTION(F)) {
419 throw %MakeTypeError('instanceof_function_expected', [F]);
422 // If V is not an object, return false.
423 if (!IS_SPEC_OBJECT(V)) {
427 // Check if function is bound, if so, get [[BoundFunction]] from it
428 // and use that instead of F.
429 var bindings = %BoundFunctionGetBindings(F);
431 F = bindings[kBoundFunctionIndex]; // Always a non-bound function.
433 // Get the prototype of F; if it is not an object, throw an error.
435 if (!IS_SPEC_OBJECT(O)) {
436 throw %MakeTypeError('instanceof_nonobject_proto', [O]);
439 // Return whether or not O is in the prototype chain of V.
440 return %IsInPrototypeChain(O, V) ? 0 : 1;
444 // Filter a given key against an object by checking if the object
445 // has a property with the given key; return the key as a string if
446 // it has. Otherwise returns 0 (smi). Used in for-in statements.
447 function FILTER_KEY(key) {
448 var string = %ToName(key);
449 if (%HasProperty(this, string)) return string;
454 function CALL_NON_FUNCTION() {
455 var delegate = %GetFunctionDelegate(this);
456 if (!IS_FUNCTION(delegate)) {
457 throw %MakeTypeError('called_non_callable', [typeof this]);
459 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength());
463 function CALL_NON_FUNCTION_AS_CONSTRUCTOR() {
464 var delegate = %GetConstructorDelegate(this);
465 if (!IS_FUNCTION(delegate)) {
466 throw %MakeTypeError('called_non_callable', [typeof this]);
468 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength());
472 function CALL_FUNCTION_PROXY() {
473 var arity = %_ArgumentsLength() - 1;
474 var proxy = %_Arguments(arity); // The proxy comes in as an additional arg.
475 var trap = %GetCallTrap(proxy);
476 return %Apply(trap, this, arguments, 0, arity);
480 function CALL_FUNCTION_PROXY_AS_CONSTRUCTOR() {
482 var trap = %GetConstructTrap(proxy);
483 return %Apply(trap, this, arguments, 0, %_ArgumentsLength());
487 function APPLY_PREPARE(args) {
489 // First check whether length is a positive Smi and args is an
490 // array. This is the fast case. If this fails, we do the slow case
491 // that takes care of more eventualities.
492 if (IS_ARRAY(args)) {
493 length = args.length;
494 if (%_IsSmi(length) && length >= 0 && length < 0x800000 &&
495 IS_SPEC_FUNCTION(this)) {
500 length = (args == null) ? 0 : %ToUint32(args.length);
502 // We can handle any number of apply arguments if the stack is
503 // big enough, but sanity check the value to avoid overflow when
504 // multiplying with pointer size.
505 if (length > 0x800000) {
506 throw %MakeRangeError('stack_overflow', []);
509 if (!IS_SPEC_FUNCTION(this)) {
510 throw %MakeTypeError('apply_non_function',
511 [ %ToString(this), typeof this ]);
514 // Make sure the arguments list has the right type.
515 if (args != null && !IS_SPEC_OBJECT(args)) {
516 throw %MakeTypeError('apply_wrong_args', []);
519 // Return the length which is the number of arguments to copy to the
520 // stack. It is guaranteed to be a small integer at this point.
525 function STACK_OVERFLOW(length) {
526 throw %MakeRangeError('stack_overflow', []);
530 // Convert the receiver to an object - forward to ToObject.
531 function TO_OBJECT() {
532 return %ToObject(this);
536 // Convert the receiver to a number - forward to ToNumber.
537 function TO_NUMBER() {
538 return %ToNumber(this);
542 // Convert the receiver to a string - forward to ToString.
543 function TO_STRING() {
544 return %ToString(this);
548 /* -------------------------------------
549 - - - C o n v e r s i o n s - - -
550 -------------------------------------
553 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint,
554 // (1) for number hint, and (2) for string hint.
555 function ToPrimitive(x, hint) {
557 if (IS_STRING(x)) return x;
559 if (!IS_SPEC_OBJECT(x)) return x;
560 if (IS_SYMBOL_WRAPPER(x)) throw MakeTypeError('symbol_to_primitive', []);
561 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT;
562 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x);
566 // ECMA-262, section 9.2, page 30
567 function ToBoolean(x) {
568 if (IS_BOOLEAN(x)) return x;
569 if (IS_STRING(x)) return x.length != 0;
570 if (x == null) return false;
571 if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x));
576 // ECMA-262, section 9.3, page 31.
577 function ToNumber(x) {
578 if (IS_NUMBER(x)) return x;
580 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x)
581 : %StringToNumber(x);
583 if (IS_BOOLEAN(x)) return x ? 1 : 0;
584 if (IS_UNDEFINED(x)) return NAN;
585 if (IS_SYMBOL(x)) return NAN;
586 if (IsFloat32x4(x)) return NAN;
587 if (IsFloat64x2(x)) return NAN;
588 if (IsInt32x4(x)) return NAN;
589 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x));
592 function NonNumberToNumber(x) {
594 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x)
595 : %StringToNumber(x);
597 if (IS_BOOLEAN(x)) return x ? 1 : 0;
598 if (IS_UNDEFINED(x)) return NAN;
599 if (IS_SYMBOL(x)) return NAN;
600 if (IsFloat32x4(x)) return NAN;
601 if (IsFloat64x2(x)) return NAN;
602 if (IsInt32x4(x)) return NAN;
603 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x));
607 // ECMA-262, section 9.8, page 35.
608 function ToString(x) {
609 if (IS_STRING(x)) return x;
610 if (IS_NUMBER(x)) return %_NumberToString(x);
611 if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
612 if (IS_UNDEFINED(x)) return 'undefined';
613 if (IS_SYMBOL(x)) throw %MakeTypeError('symbol_to_string', []);
614 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x));
617 function NonStringToString(x) {
618 if (IS_NUMBER(x)) return %_NumberToString(x);
619 if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
620 if (IS_UNDEFINED(x)) return 'undefined';
621 if (IS_SYMBOL(x)) throw %MakeTypeError('symbol_to_string', []);
622 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x));
628 return IS_SYMBOL(x) ? x : %ToString(x);
632 // ECMA-262, section 9.9, page 36.
633 function ToObject(x) {
634 if (IS_STRING(x)) return new $String(x);
635 if (IS_NUMBER(x)) return new $Number(x);
636 if (IS_BOOLEAN(x)) return new $Boolean(x);
637 if (IsFloat32x4(x)) return new $Float32x4(x.x, x.y, x.z, x.w);
638 if (IsFloat64x2(x)) return new $Float64x2(x.x, x.y);
639 if (IsInt32x4(x)) return new $Int32x4(x.x, x.y, x.z, x.w);
640 if (IS_SYMBOL(x)) return %NewSymbolWrapper(x);
641 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) {
642 throw %MakeTypeError('undefined_or_null_to_object', []);
648 // ECMA-262, section 9.4, page 34.
649 function ToInteger(x) {
650 if (%_IsSmi(x)) return x;
651 return %NumberToInteger(ToNumber(x));
655 // ECMA-262, section 9.6, page 34.
656 function ToUint32(x) {
657 if (%_IsSmi(x) && x >= 0) return x;
658 return %NumberToJSUint32(ToNumber(x));
662 // ECMA-262, section 9.5, page 34
663 function ToInt32(x) {
664 if (%_IsSmi(x)) return x;
665 return %NumberToJSInt32(ToNumber(x));
670 function SameValue(x, y) {
671 if (typeof x != typeof y) return false;
673 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true;
674 // x is +0 and y is -0 or vice versa.
675 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) {
683 /* ---------------------------------
684 - - - U t i l i t i e s - - -
685 ---------------------------------
688 // Returns if the given x is a primitive value - not an object or a
690 function IsPrimitive(x) {
691 // Even though the type of null is "object", null is still
692 // considered a primitive value. IS_SPEC_OBJECT handles this correctly
693 // (i.e., it will return false if x is null).
694 return !IS_SPEC_OBJECT(x);
698 // ECMA-262, section 8.6.2.6, page 28.
699 function DefaultNumber(x) {
700 var valueOf = x.valueOf;
701 if (IS_SPEC_FUNCTION(valueOf)) {
702 var v = %_CallFunction(x, valueOf);
703 if (%IsPrimitive(v)) return v;
706 var toString = x.toString;
707 if (IS_SPEC_FUNCTION(toString)) {
708 var s = %_CallFunction(x, toString);
709 if (%IsPrimitive(s)) return s;
712 throw %MakeTypeError('cannot_convert_to_primitive', []);
715 // ECMA-262, section 8.6.2.6, page 28.
716 function DefaultString(x) {
717 var toString = x.toString;
718 if (IS_SPEC_FUNCTION(toString)) {
719 var s = %_CallFunction(x, toString);
720 if (%IsPrimitive(s)) return s;
723 var valueOf = x.valueOf;
724 if (IS_SPEC_FUNCTION(valueOf)) {
725 var v = %_CallFunction(x, valueOf);
726 if (%IsPrimitive(v)) return v;
729 throw %MakeTypeError('cannot_convert_to_primitive', []);
732 function ToPositiveInteger(x, rangeErrorName) {
733 var i = TO_INTEGER(x);
734 if (i < 0) throw MakeRangeError(rangeErrorName);
739 // NOTE: Setting the prototype for Array must take place as early as
740 // possible due to code generation for array literals. When
741 // generating code for a array literal a boilerplate array is created
742 // that is cloned when running the code. It is essential that the
743 // boilerplate gets the right prototype.
744 %FunctionSetPrototype($Array, new $Array(0));