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 // 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 // This files contains runtime support implemented in JavaScript. | 5 // This files contains runtime support implemented in JavaScript. |
6 | 6 |
7 // CAUTION: Some of the functions specified in this file are called | 7 // CAUTION: Some of the functions specified in this file are called |
8 // directly from compiled code. These are the functions with names in | 8 // directly from compiled code. These are the functions with names in |
9 // ALL CAPS. The compiled code passes the first argument in 'this'. | 9 // ALL CAPS. The compiled code passes the first argument in 'this'. |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 MakeRangeError = from.MakeRangeError; | 27 MakeRangeError = from.MakeRangeError; |
28 }); | 28 }); |
29 | 29 |
30 // ---------------------------------------------------------------------------- | 30 // ---------------------------------------------------------------------------- |
31 | 31 |
32 /* ----------------------------- | 32 /* ----------------------------- |
33 - - - H e l p e r s - - - | 33 - - - H e l p e r s - - - |
34 ----------------------------- | 34 ----------------------------- |
35 */ | 35 */ |
36 | 36 |
| 37 function APPLY_PREPARE(args) { |
| 38 var length; |
| 39 |
| 40 // First check that the receiver is callable. |
| 41 if (!IS_CALLABLE(this)) { |
| 42 throw %make_type_error(kApplyNonFunction, TO_STRING(this), typeof this); |
| 43 } |
| 44 |
| 45 // First check whether length is a positive Smi and args is an |
| 46 // array. This is the fast case. If this fails, we do the slow case |
| 47 // that takes care of more eventualities. |
| 48 if (IS_ARRAY(args)) { |
| 49 length = args.length; |
| 50 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength) { |
| 51 return length; |
| 52 } |
| 53 } |
| 54 |
| 55 length = (args == null) ? 0 : TO_UINT32(args.length); |
| 56 |
| 57 // We can handle any number of apply arguments if the stack is |
| 58 // big enough, but sanity check the value to avoid overflow when |
| 59 // multiplying with pointer size. |
| 60 if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow); |
| 61 |
| 62 // Make sure the arguments list has the right type. |
| 63 if (args != null && !IS_SPEC_OBJECT(args)) { |
| 64 throw %make_type_error(kWrongArgs, "Function.prototype.apply"); |
| 65 } |
| 66 |
| 67 // Return the length which is the number of arguments to copy to the |
| 68 // stack. It is guaranteed to be a small integer at this point. |
| 69 return length; |
| 70 } |
| 71 |
| 72 |
| 73 function REFLECT_APPLY_PREPARE(args) { |
| 74 var length; |
| 75 |
| 76 // First check that the receiver is callable. |
| 77 if (!IS_CALLABLE(this)) { |
| 78 throw %make_type_error(kApplyNonFunction, TO_STRING(this), typeof this); |
| 79 } |
| 80 |
| 81 // First check whether length is a positive Smi and args is an |
| 82 // array. This is the fast case. If this fails, we do the slow case |
| 83 // that takes care of more eventualities. |
| 84 if (IS_ARRAY(args)) { |
| 85 length = args.length; |
| 86 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength) { |
| 87 return length; |
| 88 } |
| 89 } |
| 90 |
| 91 if (!IS_SPEC_OBJECT(args)) { |
| 92 throw %make_type_error(kWrongArgs, "Reflect.apply"); |
| 93 } |
| 94 |
| 95 length = TO_LENGTH(args.length); |
| 96 |
| 97 // We can handle any number of apply arguments if the stack is |
| 98 // big enough, but sanity check the value to avoid overflow when |
| 99 // multiplying with pointer size. |
| 100 if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow); |
| 101 |
| 102 // Return the length which is the number of arguments to copy to the |
| 103 // stack. It is guaranteed to be a small integer at this point. |
| 104 return length; |
| 105 } |
| 106 |
| 107 |
| 108 function REFLECT_CONSTRUCT_PREPARE( |
| 109 args, newTarget) { |
| 110 var length; |
| 111 var ctorOk = IS_CALLABLE(this) && %IsConstructor(this); |
| 112 var newTargetOk = IS_CALLABLE(newTarget) && %IsConstructor(newTarget); |
| 113 |
| 114 // First check whether length is a positive Smi and args is an |
| 115 // array. This is the fast case. If this fails, we do the slow case |
| 116 // that takes care of more eventualities. |
| 117 if (IS_ARRAY(args)) { |
| 118 length = args.length; |
| 119 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && |
| 120 ctorOk && newTargetOk) { |
| 121 return length; |
| 122 } |
| 123 } |
| 124 |
| 125 if (!ctorOk) { |
| 126 if (!IS_CALLABLE(this)) { |
| 127 throw %make_type_error(kCalledNonCallable, TO_STRING(this)); |
| 128 } else { |
| 129 throw %make_type_error(kNotConstructor, TO_STRING(this)); |
| 130 } |
| 131 } |
| 132 |
| 133 if (!newTargetOk) { |
| 134 if (!IS_CALLABLE(newTarget)) { |
| 135 throw %make_type_error(kCalledNonCallable, TO_STRING(newTarget)); |
| 136 } else { |
| 137 throw %make_type_error(kNotConstructor, TO_STRING(newTarget)); |
| 138 } |
| 139 } |
| 140 |
| 141 if (!IS_SPEC_OBJECT(args)) { |
| 142 throw %make_type_error(kWrongArgs, "Reflect.construct"); |
| 143 } |
| 144 |
| 145 length = TO_LENGTH(args.length); |
| 146 |
| 147 // We can handle any number of apply arguments if the stack is |
| 148 // big enough, but sanity check the value to avoid overflow when |
| 149 // multiplying with pointer size. |
| 150 if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow); |
| 151 |
| 152 // Return the length which is the number of arguments to copy to the |
| 153 // stack. It is guaranteed to be a small integer at this point. |
| 154 return length; |
| 155 } |
| 156 |
| 157 |
37 function CONCAT_ITERABLE_TO_ARRAY(iterable) { | 158 function CONCAT_ITERABLE_TO_ARRAY(iterable) { |
38 return %concat_iterable_to_array(this, iterable); | 159 return %concat_iterable_to_array(this, iterable); |
39 }; | 160 }; |
40 | 161 |
41 | 162 |
42 /* ------------------------------------- | 163 /* ------------------------------------- |
43 - - - C o n v e r s i o n s - - - | 164 - - - C o n v e r s i o n s - - - |
44 ------------------------------------- | 165 ------------------------------------- |
45 */ | 166 */ |
46 | 167 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 utils.Export(function(to) { | 254 utils.Export(function(to) { |
134 to.AddIndexedProperty = AddIndexedProperty; | 255 to.AddIndexedProperty = AddIndexedProperty; |
135 to.MaxSimple = MaxSimple; | 256 to.MaxSimple = MaxSimple; |
136 to.MinSimple = MinSimple; | 257 to.MinSimple = MinSimple; |
137 to.SameValue = SameValue; | 258 to.SameValue = SameValue; |
138 to.SameValueZero = SameValueZero; | 259 to.SameValueZero = SameValueZero; |
139 to.ToPositiveInteger = ToPositiveInteger; | 260 to.ToPositiveInteger = ToPositiveInteger; |
140 }); | 261 }); |
141 | 262 |
142 %InstallToContext([ | 263 %InstallToContext([ |
| 264 "apply_prepare_builtin", APPLY_PREPARE, |
143 "concat_iterable_to_array_builtin", CONCAT_ITERABLE_TO_ARRAY, | 265 "concat_iterable_to_array_builtin", CONCAT_ITERABLE_TO_ARRAY, |
| 266 "reflect_apply_prepare_builtin", REFLECT_APPLY_PREPARE, |
| 267 "reflect_construct_prepare_builtin", REFLECT_CONSTRUCT_PREPARE, |
144 ]); | 268 ]); |
145 | 269 |
146 %InstallToContext([ | 270 %InstallToContext([ |
147 "concat_iterable_to_array", ConcatIterableToArray, | 271 "concat_iterable_to_array", ConcatIterableToArray, |
148 ]); | 272 ]); |
149 | 273 |
150 }) | 274 }) |
OLD | NEW |