1 # Copyright 2006-2009 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are
6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above
9 # copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided
11 # with the distribution.
12 # * Neither the name of Google Inc. nor the names of its
13 # contributors may be used to endorse or promote products derived
14 # from this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 # Dictionary that is passed as defines for js2c.py.
29 # Used for defines that must be defined for all native JS files.
34 const DONT_DELETE = 4;
35 const NEW_ONE_BYTE_STRING = true;
36 const NEW_TWO_BYTE_STRING = false;
38 # Constants used for getter and setter operations.
43 const NUMBER_HINT = 1;
44 const STRING_HINT = 2;
47 const HoursPerDay = 24;
48 const MinutesPerHour = 60;
49 const SecondsPerMinute = 60;
50 const msPerSecond = 1000;
51 const msPerMinute = 60000;
52 const msPerHour = 3600000;
53 const msPerDay = 86400000;
54 const msPerMonth = 2592000000;
56 # Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1).
57 const kInvalidDate = 'Invalid Date';
58 const kDayZeroInJulianDay = 2440588;
59 const kMonthMask = 0x1e0;
60 const kDayMask = 0x01f;
62 const kMonthShift = 5;
64 # Limits for parts of the date, so that we support all the dates that
65 # ECMA 262 - 15.9.1.1 requires us to, but at the same time be sure that
66 # the date (days since 1970) is in SMI range.
67 const kMinYear = -1000000;
68 const kMaxYear = 1000000;
69 const kMinMonth = -10000000;
70 const kMaxMonth = 10000000;
72 # Safe maximum number of arguments to push to stack, when multiplied by
73 # pointer size. Used by Function.prototype.apply(), Reflect.apply() and
74 # Reflect.construct().
75 const kSafeArgumentsLength = 0x800000;
77 # Strict mode flags for passing to %SetProperty
78 const kSloppyMode = 0;
79 const kStrictMode = 1;
82 const STRING_TO_REGEXP_CACHE_ID = 0;
86 # Note: We have special support for typeof(foo) === 'bar' in the compiler.
87 # It will *not* generate a runtime typeof call for the most important
89 macro IS_NULL(arg) = (arg === null);
90 macro IS_NULL_OR_UNDEFINED(arg) = (arg == null);
91 macro IS_UNDEFINED(arg) = (arg === (void 0));
92 macro IS_NUMBER(arg) = (typeof(arg) === 'number');
93 macro IS_STRING(arg) = (typeof(arg) === 'string');
94 macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean');
95 macro IS_SYMBOL(arg) = (typeof(arg) === 'symbol');
96 macro IS_OBJECT(arg) = (%_IsObject(arg));
97 macro IS_ARRAY(arg) = (%_IsArray(arg));
98 macro IS_FUNCTION(arg) = (%_IsFunction(arg));
99 macro IS_REGEXP(arg) = (%_IsRegExp(arg));
100 macro IS_SET(arg) = (%_ClassOf(arg) === 'Set');
101 macro IS_MAP(arg) = (%_ClassOf(arg) === 'Map');
102 macro IS_WEAKMAP(arg) = (%_ClassOf(arg) === 'WeakMap');
103 macro IS_WEAKSET(arg) = (%_ClassOf(arg) === 'WeakSet');
104 macro IS_DATE(arg) = (%_ClassOf(arg) === 'Date');
105 macro IS_NUMBER_WRAPPER(arg) = (%_ClassOf(arg) === 'Number');
106 macro IS_STRING_WRAPPER(arg) = (%_ClassOf(arg) === 'String');
107 macro IS_SYMBOL_WRAPPER(arg) = (%_ClassOf(arg) === 'Symbol');
108 macro IS_BOOLEAN_WRAPPER(arg) = (%_ClassOf(arg) === 'Boolean');
109 macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error');
110 macro IS_SCRIPT(arg) = (%_ClassOf(arg) === 'Script');
111 macro IS_ARGUMENTS(arg) = (%_ClassOf(arg) === 'Arguments');
112 macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global');
113 macro IS_ARRAYBUFFER(arg) = (%_ClassOf(arg) === 'ArrayBuffer');
114 macro IS_DATAVIEW(arg) = (%_ClassOf(arg) === 'DataView');
115 macro IS_GENERATOR(arg) = (%_ClassOf(arg) === 'Generator');
116 macro IS_SET_ITERATOR(arg) = (%_ClassOf(arg) === 'Set Iterator');
117 macro IS_MAP_ITERATOR(arg) = (%_ClassOf(arg) === 'Map Iterator');
118 macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg));
120 # Macro for ECMAScript 5 queries of the type:
121 # "Type(O) is object."
122 # This is the same as being either a function or an object in V8 terminology
123 # (including proxies).
124 # In addition, an undetectable object is also included by this.
125 macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg));
127 # Macro for ECMAScript 5 queries of the type:
129 # We assume here that this is the same as being either a function or a function
130 # proxy. That ignores host objects with [[Call]] methods, but in most situations
131 # we cannot handle those anyway.
132 macro IS_SPEC_FUNCTION(arg) = (%_ClassOf(arg) === 'Function');
134 # Macro for ES6 CheckObjectCoercible
135 # Will throw a TypeError of the form "[functionName] called on null or undefined".
136 macro CHECK_OBJECT_COERCIBLE(arg, functionName) = if (IS_NULL_OR_UNDEFINED(arg) && !IS_UNDETECTABLE(arg)) throw MakeTypeError('called_on_null_or_undefined', [functionName]);
138 # Indices in bound function info retrieved by %BoundFunctionGetBindings(...).
139 const kBoundFunctionIndex = 0;
140 const kBoundThisIndex = 1;
141 const kBoundArgumentsStartIndex = 2;
143 # Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
144 macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
145 macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0)));
146 macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg)));
147 macro TO_INTEGER_FOR_SIDE_EFFECT(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToNumber(arg));
148 macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
149 macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));
150 macro TO_UINT32(arg) = (arg >>> 0);
151 macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg));
152 macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : NonNumberToNumber(arg));
153 macro TO_OBJECT_INLINE(arg) = (IS_SPEC_OBJECT(%IS_VAR(arg)) ? arg : ToObject(arg));
154 macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null");
155 macro HAS_OWN_PROPERTY(obj, index) = (%_CallFunction(obj, index, ObjectHasOwnProperty));
156 macro SHOULD_CREATE_WRAPPER(functionName, receiver) = (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(functionName));
157 macro HAS_INDEX(array, index, is_array) = ((is_array && %_HasFastPackedElements(%IS_VAR(array))) ? (index < array.length) : (index in array));
160 # GET_PRIVATE should only be used if the property is known to exists on obj
161 # itself (it should really use %GetOwnProperty, but that would be way slower).
162 macro GLOBAL_PRIVATE(name) = (%CreateGlobalPrivateOwnSymbol(name));
163 macro NEW_PRIVATE_OWN(name) = (%CreatePrivateOwnSymbol(name));
164 macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym));
165 macro HAS_PRIVATE(obj, sym) = (%HasOwnProperty(obj, sym));
166 macro HAS_DEFINED_PRIVATE(obj, sym) = (!IS_UNDEFINED(obj[sym]));
167 macro GET_PRIVATE(obj, sym) = (obj[sym]);
168 macro SET_PRIVATE(obj, sym, val) = (obj[sym] = val);
169 macro DELETE_PRIVATE(obj, sym) = (delete obj[sym]);
171 # Constants. The compiler constant folds them.
173 const INFINITY = (1/0);
174 const UNDEFINED = (void 0);
176 # Macros implemented in Python.
177 python macro CHAR_CODE(str) = ord(str[1]);
179 # Constants used on an array to implement the properties of the RegExp object.
180 const REGEXP_NUMBER_OF_CAPTURES = 0;
181 const REGEXP_FIRST_CAPTURE = 3;
183 # We can't put macros in macros so we use constants here.
184 # REGEXP_NUMBER_OF_CAPTURES
185 macro NUMBER_OF_CAPTURES(array) = ((array)[0]);
187 # Limit according to ECMA 262 15.9.1.1
188 const MAX_TIME_MS = 8640000000000000;
189 # Limit which is MAX_TIME_MS + msPerMonth.
190 const MAX_TIME_BEFORE_UTC = 8640002592000000;
192 # Gets the value of a Date object. If arg is not a Date object
193 # a type error is thrown.
194 macro CHECK_DATE(arg) = if (%_ClassOf(arg) !== 'Date') ThrowDateTypeError();
195 macro LOCAL_DATE_VALUE(arg) = (%_DateField(arg, 0) + %_DateField(arg, 21));
196 macro UTC_DATE_VALUE(arg) = (%_DateField(arg, 0));
198 macro LOCAL_YEAR(arg) = (%_DateField(arg, 1));
199 macro LOCAL_MONTH(arg) = (%_DateField(arg, 2));
200 macro LOCAL_DAY(arg) = (%_DateField(arg, 3));
201 macro LOCAL_WEEKDAY(arg) = (%_DateField(arg, 4));
202 macro LOCAL_HOUR(arg) = (%_DateField(arg, 5));
203 macro LOCAL_MIN(arg) = (%_DateField(arg, 6));
204 macro LOCAL_SEC(arg) = (%_DateField(arg, 7));
205 macro LOCAL_MS(arg) = (%_DateField(arg, 8));
206 macro LOCAL_DAYS(arg) = (%_DateField(arg, 9));
207 macro LOCAL_TIME_IN_DAY(arg) = (%_DateField(arg, 10));
209 macro UTC_YEAR(arg) = (%_DateField(arg, 11));
210 macro UTC_MONTH(arg) = (%_DateField(arg, 12));
211 macro UTC_DAY(arg) = (%_DateField(arg, 13));
212 macro UTC_WEEKDAY(arg) = (%_DateField(arg, 14));
213 macro UTC_HOUR(arg) = (%_DateField(arg, 15));
214 macro UTC_MIN(arg) = (%_DateField(arg, 16));
215 macro UTC_SEC(arg) = (%_DateField(arg, 17));
216 macro UTC_MS(arg) = (%_DateField(arg, 18));
217 macro UTC_DAYS(arg) = (%_DateField(arg, 19));
218 macro UTC_TIME_IN_DAY(arg) = (%_DateField(arg, 20));
220 macro TIMEZONE_OFFSET(arg) = (%_DateField(arg, 21));
222 macro SET_UTC_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 1));
223 macro SET_LOCAL_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 0));
225 # Last input and last subject of regexp matches.
226 const LAST_SUBJECT_INDEX = 1;
227 macro LAST_SUBJECT(array) = ((array)[1]);
228 macro LAST_INPUT(array) = ((array)[2]);
230 # REGEXP_FIRST_CAPTURE
231 macro CAPTURE(index) = (3 + (index));
235 # For the regexp capture override array. This has the same
236 # format as the arguments to a function called from
237 # String.prototype.replace.
238 macro OVERRIDE_MATCH(override) = ((override)[0]);
239 macro OVERRIDE_POS(override) = ((override)[(override).length - 2]);
240 macro OVERRIDE_SUBJECT(override) = ((override)[(override).length - 1]);
241 # 1-based so index of 1 returns the first capture
242 macro OVERRIDE_CAPTURE(override, index) = ((override)[(index)]);
244 # PropertyDescriptor return value indices - must match
245 # PropertyDescriptorIndices in runtime-object.cc.
246 const IS_ACCESSOR_INDEX = 0;
247 const VALUE_INDEX = 1;
248 const GETTER_INDEX = 2;
249 const SETTER_INDEX = 3;
250 const WRITABLE_INDEX = 4;
251 const ENUMERABLE_INDEX = 5;
252 const CONFIGURABLE_INDEX = 6;
255 # Matches Script::Type from objects.h
256 const TYPE_NATIVE = 0;
257 const TYPE_EXTENSION = 1;
258 const TYPE_NORMAL = 2;
260 # Matches Script::CompilationType from objects.h
261 const COMPILATION_TYPE_HOST = 0;
262 const COMPILATION_TYPE_EVAL = 1;
263 const COMPILATION_TYPE_JSON = 2;
265 # Matches Messages::kNoLineNumberInfo from v8.h
266 const kNoLineNumberInfo = 0;
268 # Matches PropertyAttributes from property-details.h
269 const PROPERTY_ATTRIBUTES_NONE = 0;
270 const PROPERTY_ATTRIBUTES_STRING = 8;
271 const PROPERTY_ATTRIBUTES_SYMBOLIC = 16;
272 const PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL = 32;
274 # Use for keys, values and entries iterators.
275 const ITERATOR_KIND_KEYS = 1;
276 const ITERATOR_KIND_VALUES = 2;
277 const ITERATOR_KIND_ENTRIES = 3;
279 # Check whether debug is active.
280 const DEBUG_IS_ACTIVE = (%_DebugIsActive() != 0);
281 macro DEBUG_IS_STEPPING(function) = (%_DebugIsActive() != 0 && %DebugCallbackSupportsStepping(function));
282 macro DEBUG_PREPARE_STEP_IN_IF_STEPPING(function) = if (DEBUG_IS_STEPPING(function)) %DebugPrepareStepInIfStepping(function);