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 define DONT_DELETE = 4;
35 define NEW_ONE_BYTE_STRING = true;
36 define NEW_TWO_BYTE_STRING = false;
38 # Constants used for getter and setter operations.
43 define HoursPerDay = 24;
44 define MinutesPerHour = 60;
45 define SecondsPerMinute = 60;
46 define msPerSecond = 1000;
47 define msPerMinute = 60000;
48 define msPerHour = 3600000;
49 define msPerDay = 86400000;
50 define msPerMonth = 2592000000;
52 # Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1).
53 define kInvalidDate = 'Invalid Date';
54 define kDayZeroInJulianDay = 2440588;
55 define kMonthMask = 0x1e0;
56 define kDayMask = 0x01f;
57 define kYearShift = 9;
58 define kMonthShift = 5;
60 # Limits for parts of the date, so that we support all the dates that
61 # ECMA 262 - 15.9.1.1 requires us to, but at the same time be sure that
62 # the date (days since 1970) is in SMI range.
63 define kMinYear = -1000000;
64 define kMaxYear = 1000000;
65 define kMinMonth = -10000000;
66 define kMaxMonth = 10000000;
68 # Safe maximum number of arguments to push to stack, when multiplied by
69 # pointer size. Used by Function.prototype.apply(), Reflect.apply() and
70 # Reflect.construct().
71 define kSafeArgumentsLength = 0x800000;
74 define kMaxSafeInteger = 9007199254740991;
76 # Strict mode flags for passing to %SetProperty
77 define kSloppyMode = 0;
78 define kStrictMode = 1;
81 define STRING_TO_REGEXP_CACHE_ID = 0;
85 # Note: We have special support for typeof(foo) === 'bar' in the compiler.
86 # It will *not* generate a runtime typeof call for the most important
88 macro IS_NULL(arg) = (arg === null);
89 macro IS_NULL_OR_UNDEFINED(arg) = (arg == null);
90 macro IS_UNDEFINED(arg) = (arg === (void 0));
91 macro IS_NUMBER(arg) = (typeof(arg) === 'number');
92 macro IS_STRING(arg) = (typeof(arg) === 'string');
93 macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean');
94 macro IS_SYMBOL(arg) = (typeof(arg) === 'symbol');
95 macro IS_OBJECT(arg) = (typeof(arg) === 'object');
96 macro IS_ARRAY(arg) = (%_IsArray(arg));
97 macro IS_DATE(arg) = (%_IsDate(arg));
98 macro IS_FUNCTION(arg) = (%_IsFunction(arg));
99 macro IS_REGEXP(arg) = (%_IsRegExp(arg));
100 macro IS_SIMD_VALUE(arg) = (%_IsSimdValue(arg));
101 macro IS_SET(arg) = (%_ClassOf(arg) === 'Set');
102 macro IS_MAP(arg) = (%_ClassOf(arg) === 'Map');
103 macro IS_WEAKMAP(arg) = (%_ClassOf(arg) === 'WeakMap');
104 macro IS_WEAKSET(arg) = (%_ClassOf(arg) === 'WeakSet');
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_SHAREDARRAYBUFFER(arg) = (%_ClassOf(arg) === 'SharedArrayBuffer');
116 macro IS_GENERATOR(arg) = (%_ClassOf(arg) === 'Generator');
117 macro IS_SET_ITERATOR(arg) = (%_ClassOf(arg) === 'Set Iterator');
118 macro IS_MAP_ITERATOR(arg) = (%_ClassOf(arg) === 'Map Iterator');
119 macro IS_STRONG(arg) = (%IsStrong(arg));
121 # Macro for ECMAScript 5 queries of the type:
122 # "Type(O) is object."
123 # This is the same as being either a function or an object in V8 terminology
124 # (including proxies).
125 # In addition, an undetectable object is also included by this.
126 macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg));
128 # Macro for ECMAScript 5 queries of the type:
130 macro IS_CALLABLE(arg) = (typeof(arg) === 'function');
132 # Macro for ES6 CheckObjectCoercible
133 # Will throw a TypeError of the form "[functionName] called on null or undefined".
134 macro CHECK_OBJECT_COERCIBLE(arg, functionName) = if (IS_NULL(%IS_VAR(arg)) || IS_UNDEFINED(arg)) throw MakeTypeError(kCalledOnNullOrUndefined, functionName);
136 # Indices in bound function info retrieved by %BoundFunctionGetBindings(...).
137 define kBoundFunctionIndex = 0;
138 define kBoundThisIndex = 1;
139 define kBoundArgumentsStartIndex = 2;
141 # Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
142 macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
143 macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0)));
144 macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg)));
145 macro TO_INTEGER_FOR_SIDE_EFFECT(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToNumber(arg));
146 macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
147 macro TO_INT32(arg) = (arg | 0);
148 macro TO_UINT32(arg) = (arg >>> 0);
149 macro TO_LENGTH_OR_UINT32(arg) = (harmony_tolength ? $toLength(arg) : TO_UINT32(arg));
150 macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : $nonStringToString(arg));
151 macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : $nonNumberToNumber(arg));
152 macro TO_OBJECT(arg) = (%_ToObject(arg));
153 macro TO_PRIMITIVE(arg) = (%_ToPrimitive(arg));
154 macro TO_PRIMITIVE_NUMBER(arg) = (%_ToPrimitive_Number(arg));
155 macro TO_PRIMITIVE_STRING(arg) = (%_ToPrimitive_String(arg));
156 macro TO_NAME(arg) = (%_ToName(arg));
157 macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null");
158 macro HAS_OWN_PROPERTY(arg, index) = (%_CallFunction(arg, index, ObjectHasOwnProperty));
159 macro HAS_INDEX(array, index, is_array) = ((is_array && %_HasFastPackedElements(%IS_VAR(array))) ? (index < array.length) : (index in array));
160 macro MAX_SIMPLE(argA, argB) = (argA < argB ? argB : argA);
161 macro MIN_SIMPLE(argA, argB) = (argA < argB ? argA : argB);
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);
170 # Constants. The compiler constant folds them.
172 define INFINITY = (1/0);
173 define UNDEFINED = (void 0);
175 # Macros implemented in Python.
176 python macro CHAR_CODE(str) = ord(str[1]);
178 # Constants used on an array to implement the properties of the RegExp object.
179 define REGEXP_NUMBER_OF_CAPTURES = 0;
180 define REGEXP_FIRST_CAPTURE = 3;
182 # We can't put macros in macros so we use constants here.
183 # REGEXP_NUMBER_OF_CAPTURES
184 macro NUMBER_OF_CAPTURES(array) = ((array)[0]);
186 # Limit according to ECMA 262 15.9.1.1
187 define MAX_TIME_MS = 8640000000000000;
188 # Limit which is MAX_TIME_MS + msPerMonth.
189 define MAX_TIME_BEFORE_UTC = 8640002592000000;
191 # Gets the value of a Date object. If arg is not a Date object
192 # a type error is thrown.
193 macro CHECK_DATE(arg) = if (!%_IsDate(arg)) %_ThrowNotDateError();
194 macro LOCAL_DATE_VALUE(arg) = (%_DateField(arg, 0) + %_DateField(arg, 21));
195 macro UTC_DATE_VALUE(arg) = (%_DateField(arg, 0));
197 macro LOCAL_YEAR(arg) = (%_DateField(arg, 1));
198 macro LOCAL_MONTH(arg) = (%_DateField(arg, 2));
199 macro LOCAL_DAY(arg) = (%_DateField(arg, 3));
200 macro LOCAL_WEEKDAY(arg) = (%_DateField(arg, 4));
201 macro LOCAL_HOUR(arg) = (%_DateField(arg, 5));
202 macro LOCAL_MIN(arg) = (%_DateField(arg, 6));
203 macro LOCAL_SEC(arg) = (%_DateField(arg, 7));
204 macro LOCAL_MS(arg) = (%_DateField(arg, 8));
205 macro LOCAL_DAYS(arg) = (%_DateField(arg, 9));
206 macro LOCAL_TIME_IN_DAY(arg) = (%_DateField(arg, 10));
208 macro UTC_YEAR(arg) = (%_DateField(arg, 11));
209 macro UTC_MONTH(arg) = (%_DateField(arg, 12));
210 macro UTC_DAY(arg) = (%_DateField(arg, 13));
211 macro UTC_WEEKDAY(arg) = (%_DateField(arg, 14));
212 macro UTC_HOUR(arg) = (%_DateField(arg, 15));
213 macro UTC_MIN(arg) = (%_DateField(arg, 16));
214 macro UTC_SEC(arg) = (%_DateField(arg, 17));
215 macro UTC_MS(arg) = (%_DateField(arg, 18));
216 macro UTC_DAYS(arg) = (%_DateField(arg, 19));
217 macro UTC_TIME_IN_DAY(arg) = (%_DateField(arg, 20));
219 macro TIMEZONE_OFFSET(arg) = (%_DateField(arg, 21));
221 macro SET_UTC_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 1));
222 macro SET_LOCAL_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 0));
224 # Last input and last subject of regexp matches.
225 define LAST_SUBJECT_INDEX = 1;
226 macro LAST_SUBJECT(array) = ((array)[1]);
227 macro LAST_INPUT(array) = ((array)[2]);
229 # REGEXP_FIRST_CAPTURE
230 macro CAPTURE(index) = (3 + (index));
234 # For the regexp capture override array. This has the same
235 # format as the arguments to a function called from
236 # String.prototype.replace.
237 macro OVERRIDE_MATCH(override) = ((override)[0]);
238 macro OVERRIDE_POS(override) = ((override)[(override).length - 2]);
239 macro OVERRIDE_SUBJECT(override) = ((override)[(override).length - 1]);
240 # 1-based so index of 1 returns the first capture
241 macro OVERRIDE_CAPTURE(override, index) = ((override)[(index)]);
243 # PropertyDescriptor return value indices - must match
244 # PropertyDescriptorIndices in runtime-object.cc.
245 define IS_ACCESSOR_INDEX = 0;
246 define VALUE_INDEX = 1;
247 define GETTER_INDEX = 2;
248 define SETTER_INDEX = 3;
249 define WRITABLE_INDEX = 4;
250 define ENUMERABLE_INDEX = 5;
251 define CONFIGURABLE_INDEX = 6;
254 # Matches Script::Type from objects.h
255 define TYPE_NATIVE = 0;
256 define TYPE_EXTENSION = 1;
257 define TYPE_NORMAL = 2;
259 # Matches Script::CompilationType from objects.h
260 define COMPILATION_TYPE_HOST = 0;
261 define COMPILATION_TYPE_EVAL = 1;
262 define COMPILATION_TYPE_JSON = 2;
264 # Matches Messages::kNoLineNumberInfo from v8.h
265 define kNoLineNumberInfo = 0;
267 # Matches PropertyAttributes from property-details.h
268 define PROPERTY_ATTRIBUTES_NONE = 0;
269 define PROPERTY_ATTRIBUTES_STRING = 8;
270 define PROPERTY_ATTRIBUTES_SYMBOLIC = 16;
271 define PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL = 32;
273 # Use for keys, values and entries iterators.
274 define ITERATOR_KIND_KEYS = 1;
275 define ITERATOR_KIND_VALUES = 2;
276 define ITERATOR_KIND_ENTRIES = 3;
278 macro FIXED_ARRAY_GET(array, index) = (%_FixedArrayGet(array, (index) | 0));
279 macro FIXED_ARRAY_SET(array, index, value) = (%_FixedArraySet(array, (index) | 0, value));
280 # TODO(adamk): Find a more robust way to force Smi representation.
281 macro FIXED_ARRAY_SET_SMI(array, index, value) = (FIXED_ARRAY_SET(array, index, (value) | 0));
283 macro ORDERED_HASH_TABLE_BUCKET_COUNT(table) = (FIXED_ARRAY_GET(table, 0));
284 macro ORDERED_HASH_TABLE_ELEMENT_COUNT(table) = (FIXED_ARRAY_GET(table, 1));
285 macro ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, count) = (FIXED_ARRAY_SET_SMI(table, 1, count));
286 macro ORDERED_HASH_TABLE_DELETED_COUNT(table) = (FIXED_ARRAY_GET(table, 2));
287 macro ORDERED_HASH_TABLE_SET_DELETED_COUNT(table, count) = (FIXED_ARRAY_SET_SMI(table, 2, count));
288 macro ORDERED_HASH_TABLE_BUCKET_AT(table, bucket) = (FIXED_ARRAY_GET(table, 3 + (bucket)));
289 macro ORDERED_HASH_TABLE_SET_BUCKET_AT(table, bucket, entry) = (FIXED_ARRAY_SET(table, 3 + (bucket), entry));
291 macro ORDERED_HASH_TABLE_HASH_TO_BUCKET(hash, numBuckets) = (hash & ((numBuckets) - 1));
293 macro ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets) = (3 + (numBuckets) + ((entry) << 1));
294 macro ORDERED_HASH_SET_KEY_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets)));
295 macro ORDERED_HASH_SET_CHAIN_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets) + 1));
297 macro ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) = (3 + (numBuckets) + ((entry) * 3));
298 macro ORDERED_HASH_MAP_KEY_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets)));
299 macro ORDERED_HASH_MAP_VALUE_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) + 1));
300 macro ORDERED_HASH_MAP_CHAIN_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) + 2));
302 # Must match OrderedHashTable::kNotFound.
303 define NOT_FOUND = -1;
305 # Check whether debug is active.
306 define DEBUG_IS_ACTIVE = (%_DebugIsActive() != 0);
307 macro DEBUG_IS_STEPPING(function) = (%_DebugIsActive() != 0 && %DebugCallbackSupportsStepping(function));
308 macro DEBUG_PREPARE_STEP_IN_IF_STEPPING(function) = if (DEBUG_IS_STEPPING(function)) %DebugPrepareStepInIfStepping(function);
310 # SharedFlag equivalents
311 define kNotShared = false;
312 define kShared = true;