Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: src/macros.py

Issue 1398733002: Move builtin JavaScript sources into own directory. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Also move macros.py file. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/json.js ('k') | src/math.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
4 # met:
5 #
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.
15 #
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.
27
28 # Dictionary that is passed as defines for js2c.py.
29 # Used for defines that must be defined for all native JS files.
30
31 define NONE = 0;
32 define READ_ONLY = 1;
33 define DONT_ENUM = 2;
34 define DONT_DELETE = 4;
35 define NEW_ONE_BYTE_STRING = true;
36 define NEW_TWO_BYTE_STRING = false;
37
38 # Constants used for getter and setter operations.
39 define GETTER = 0;
40 define SETTER = 1;
41
42 # For date.js.
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;
51
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;
59
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;
67
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;
72
73 # 2^53 - 1
74 define kMaxSafeInteger = 9007199254740991;
75
76 # Strict mode flags for passing to %SetProperty
77 define kSloppyMode = 0;
78 define kStrictMode = 1;
79
80 # Native cache ids.
81 define STRING_TO_REGEXP_CACHE_ID = 0;
82
83 # Type query macros.
84 #
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
87 # values of 'bar'.
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));
120
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));
127
128 # Macro for ECMAScript 5 queries of the type:
129 # "IsCallable(O)"
130 macro IS_CALLABLE(arg) = (typeof(arg) === 'function');
131
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)) || I S_UNDEFINED(arg)) throw MakeTypeError(kCalledOnNullOrUndefined, functionName);
135
136 # Indices in bound function info retrieved by %BoundFunctionGetBindings(...).
137 define kBoundFunctionIndex = 0;
138 define kBoundThisIndex = 1;
139 define kBoundArgumentsStartIndex = 2;
140
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_BOOLEAN(arg) = (!!(arg));
145 macro TO_INTEGER(arg) = (%_ToInteger(arg));
146 macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToI ntegerMapMinusZero(arg));
147 macro TO_INT32(arg) = ((arg) | 0);
148 macro TO_UINT32(arg) = ((arg) >>> 0);
149 macro TO_LENGTH(arg) = (%ToLength(arg));
150 macro TO_LENGTH_OR_UINT32(arg) = (harmony_tolength ? TO_LENGTH(arg) : TO_UINT32( arg));
151 macro TO_STRING(arg) = (%_ToString(arg));
152 macro TO_NUMBER(arg) = (%_ToNumber(arg));
153 macro TO_OBJECT(arg) = (%_ToObject(arg));
154 macro TO_PRIMITIVE(arg) = (%_ToPrimitive(arg));
155 macro TO_PRIMITIVE_NUMBER(arg) = (%_ToPrimitive_Number(arg));
156 macro TO_PRIMITIVE_STRING(arg) = (%_ToPrimitive_String(arg));
157 macro TO_NAME(arg) = (%_ToName(arg));
158 macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null");
159 macro HAS_OWN_PROPERTY(arg, index) = (%_CallFunction(arg, index, ObjectHasOwnPro perty));
160 macro HAS_INDEX(array, index, is_array) = ((is_array && %_HasFastPackedElements( %IS_VAR(array))) ? (index < array.length) : (index in array));
161 macro MAX_SIMPLE(argA, argB) = (argA < argB ? argB : argA);
162 macro MIN_SIMPLE(argA, argB) = (argA < argB ? argA : argB);
163
164 # Private names.
165 macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym));
166 macro HAS_PRIVATE(obj, sym) = (%HasOwnProperty(obj, sym));
167 macro HAS_DEFINED_PRIVATE(obj, sym) = (!IS_UNDEFINED(obj[sym]));
168 macro GET_PRIVATE(obj, sym) = (obj[sym]);
169 macro SET_PRIVATE(obj, sym, val) = (obj[sym] = val);
170
171 # Constants. The compiler constant folds them.
172 define NAN = $NaN;
173 define INFINITY = (1/0);
174 define UNDEFINED = (void 0);
175
176 # Macros implemented in Python.
177 python macro CHAR_CODE(str) = ord(str[1]);
178
179 # Constants used on an array to implement the properties of the RegExp object.
180 define REGEXP_NUMBER_OF_CAPTURES = 0;
181 define REGEXP_FIRST_CAPTURE = 3;
182
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]);
186
187 # Limit according to ECMA 262 15.9.1.1
188 define MAX_TIME_MS = 8640000000000000;
189 # Limit which is MAX_TIME_MS + msPerMonth.
190 define MAX_TIME_BEFORE_UTC = 8640002592000000;
191
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 (!%_IsDate(arg)) %_ThrowNotDateError();
195 macro LOCAL_DATE_VALUE(arg) = (%_DateField(arg, 0) + %_DateField(arg, 21));
196 macro UTC_DATE_VALUE(arg) = (%_DateField(arg, 0));
197
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));
208
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));
219
220 macro TIMEZONE_OFFSET(arg) = (%_DateField(arg, 21));
221
222 macro SET_UTC_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 1));
223 macro SET_LOCAL_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 0));
224
225 # Last input and last subject of regexp matches.
226 define LAST_SUBJECT_INDEX = 1;
227 macro LAST_SUBJECT(array) = ((array)[1]);
228 macro LAST_INPUT(array) = ((array)[2]);
229
230 # REGEXP_FIRST_CAPTURE
231 macro CAPTURE(index) = (3 + (index));
232 define CAPTURE0 = 3;
233 define CAPTURE1 = 4;
234
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)]);
243
244 # PropertyDescriptor return value indices - must match
245 # PropertyDescriptorIndices in runtime-object.cc.
246 define IS_ACCESSOR_INDEX = 0;
247 define VALUE_INDEX = 1;
248 define GETTER_INDEX = 2;
249 define SETTER_INDEX = 3;
250 define WRITABLE_INDEX = 4;
251 define ENUMERABLE_INDEX = 5;
252 define CONFIGURABLE_INDEX = 6;
253
254 # For messages.js
255 # Matches Script::Type from objects.h
256 define TYPE_NATIVE = 0;
257 define TYPE_EXTENSION = 1;
258 define TYPE_NORMAL = 2;
259
260 # Matches Script::CompilationType from objects.h
261 define COMPILATION_TYPE_HOST = 0;
262 define COMPILATION_TYPE_EVAL = 1;
263 define COMPILATION_TYPE_JSON = 2;
264
265 # Matches Messages::kNoLineNumberInfo from v8.h
266 define kNoLineNumberInfo = 0;
267
268 # Matches PropertyAttributes from property-details.h
269 define PROPERTY_ATTRIBUTES_NONE = 0;
270 define PROPERTY_ATTRIBUTES_STRING = 8;
271 define PROPERTY_ATTRIBUTES_SYMBOLIC = 16;
272 define PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL = 32;
273
274 # Use for keys, values and entries iterators.
275 define ITERATOR_KIND_KEYS = 1;
276 define ITERATOR_KIND_VALUES = 2;
277 define ITERATOR_KIND_ENTRIES = 3;
278
279 macro FIXED_ARRAY_GET(array, index) = (%_FixedArrayGet(array, (index) | 0));
280 macro FIXED_ARRAY_SET(array, index, value) = (%_FixedArraySet(array, (index) | 0 , value));
281 # TODO(adamk): Find a more robust way to force Smi representation.
282 macro FIXED_ARRAY_SET_SMI(array, index, value) = (FIXED_ARRAY_SET(array, index, (value) | 0));
283
284 macro ORDERED_HASH_TABLE_BUCKET_COUNT(table) = (FIXED_ARRAY_GET(table, 0));
285 macro ORDERED_HASH_TABLE_ELEMENT_COUNT(table) = (FIXED_ARRAY_GET(table, 1));
286 macro ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, count) = (FIXED_ARRAY_SET_SMI( table, 1, count));
287 macro ORDERED_HASH_TABLE_DELETED_COUNT(table) = (FIXED_ARRAY_GET(table, 2));
288 macro ORDERED_HASH_TABLE_SET_DELETED_COUNT(table, count) = (FIXED_ARRAY_SET_SMI( table, 2, count));
289 macro ORDERED_HASH_TABLE_BUCKET_AT(table, bucket) = (FIXED_ARRAY_GET(table, 3 + (bucket)));
290 macro ORDERED_HASH_TABLE_SET_BUCKET_AT(table, bucket, entry) = (FIXED_ARRAY_SET( table, 3 + (bucket), entry));
291
292 macro ORDERED_HASH_TABLE_HASH_TO_BUCKET(hash, numBuckets) = (hash & ((numBuckets ) - 1));
293
294 macro ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets) = (3 + (numBuckets) + ( (entry) << 1));
295 macro ORDERED_HASH_SET_KEY_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table , ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets)));
296 macro ORDERED_HASH_SET_CHAIN_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(tab le, ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets) + 1));
297
298 macro ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) = (3 + (numBuckets) + ( (entry) * 3));
299 macro ORDERED_HASH_MAP_KEY_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table , ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets)));
300 macro ORDERED_HASH_MAP_VALUE_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(tab le, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) + 1));
301 macro ORDERED_HASH_MAP_CHAIN_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(tab le, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) + 2));
302
303 # Must match OrderedHashTable::kNotFound.
304 define NOT_FOUND = -1;
305
306 # Check whether debug is active.
307 define DEBUG_IS_ACTIVE = (%_DebugIsActive() != 0);
308 macro DEBUG_IS_STEPPING(function) = (%_DebugIsActive() != 0 && %DebugCallbackSup portsStepping(function));
309 macro DEBUG_PREPARE_STEP_IN_IF_STEPPING(function) = if (DEBUG_IS_STEPPING(functi on)) %DebugPrepareStepInIfStepping(function);
310
311 # SharedFlag equivalents
312 define kNotShared = false;
313 define kShared = true;
OLDNEW
« no previous file with comments | « src/json.js ('k') | src/math.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698