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
31define NONE        = 0;
32define READ_ONLY   = 1;
33define DONT_ENUM   = 2;
34define DONT_DELETE = 4;
35
36# 2^53 - 1
37define kMaxSafeInteger = 9007199254740991;
38
39# 2^32 - 1
40define kMaxUint32 = 4294967295;
41
42# Type query macros.
43#
44# Note: We have special support for typeof(foo) === 'bar' in the compiler.
45#       It will *not* generate a runtime typeof call for the most important
46#       values of 'bar'.
47macro IS_ARRAY(arg)             = (%_IsArray(arg));
48macro IS_ARRAYBUFFER(arg)       = (%_ClassOf(arg) === 'ArrayBuffer');
49macro IS_BOOLEAN(arg)           = (typeof(arg) === 'boolean');
50macro IS_DATAVIEW(arg)          = (%_ClassOf(arg) === 'DataView');
51macro IS_DATE(arg)              = (%IsDate(arg));
52macro IS_ERROR(arg)             = (%_ClassOf(arg) === 'Error');
53macro IS_FUNCTION(arg)          = (%IsFunction(arg));
54macro IS_GENERATOR(arg)         = (%_ClassOf(arg) === 'Generator');
55macro IS_GLOBAL(arg)            = (%_ClassOf(arg) === 'global');
56macro IS_MAP(arg)               = (%_ClassOf(arg) === 'Map');
57macro IS_MAP_ITERATOR(arg)      = (%_ClassOf(arg) === 'Map Iterator');
58macro IS_NULL(arg)              = (arg === null);
59macro IS_NULL_OR_UNDEFINED(arg) = (arg == null);
60macro IS_NUMBER(arg)            = (typeof(arg) === 'number');
61macro IS_OBJECT(arg)            = (typeof(arg) === 'object');
62macro IS_PROXY(arg)             = (%_IsJSProxy(arg));
63macro IS_REGEXP(arg)            = (%_IsRegExp(arg));
64macro IS_SCRIPT(arg)            = (%_ClassOf(arg) === 'Script');
65macro IS_SET(arg)               = (%_ClassOf(arg) === 'Set');
66macro IS_SET_ITERATOR(arg)      = (%_ClassOf(arg) === 'Set Iterator');
67macro IS_SHAREDARRAYBUFFER(arg) = (%_ClassOf(arg) === 'SharedArrayBuffer');
68macro IS_SIMD_VALUE(arg)        = (%IsSimdValue(arg));
69macro IS_STRING(arg)            = (typeof(arg) === 'string');
70macro IS_SYMBOL(arg)            = (typeof(arg) === 'symbol');
71macro IS_TYPEDARRAY(arg)        = (%_IsTypedArray(arg));
72macro IS_UNDEFINED(arg)         = (arg === (void 0));
73macro IS_WEAKMAP(arg)           = (%_ClassOf(arg) === 'WeakMap');
74macro IS_WEAKSET(arg)           = (%_ClassOf(arg) === 'WeakSet');
75
76# Macro for ES queries of the type: "Type(O) is Object."
77macro IS_RECEIVER(arg) = (%_IsJSReceiver(arg));
78
79# Macro for ES queries of the type: "IsCallable(O)"
80macro IS_CALLABLE(arg) = (typeof(arg) === 'function');
81
82# Macro for ES6 CheckObjectCoercible
83# Will throw a TypeError of the form "[functionName] called on null or undefined".
84macro CHECK_OBJECT_COERCIBLE(arg, functionName) = if (IS_NULL(%IS_VAR(arg)) || IS_UNDEFINED(arg)) throw %make_type_error(kCalledOnNullOrUndefined, functionName);
85
86# Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
87macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
88macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0)));
89macro TO_BOOLEAN(arg) = (!!(arg));
90macro TO_INTEGER(arg) = (%_ToInteger(arg));
91macro TO_INT32(arg) = ((arg) | 0);
92macro TO_UINT32(arg) = ((arg) >>> 0);
93macro INVERT_NEG_ZERO(arg) = ((arg) + 0);
94macro TO_LENGTH(arg) = (%_ToLength(arg));
95macro TO_STRING(arg) = (%_ToString(arg));
96macro TO_NUMBER(arg) = (%_ToNumber(arg));
97macro TO_OBJECT(arg) = (%_ToObject(arg));
98macro HAS_OWN_PROPERTY(obj, key) = (%_Call(ObjectHasOwnProperty, obj, key));
99
100# Private names.
101macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym));
102macro HAS_PRIVATE(obj, key) = HAS_OWN_PROPERTY(obj, key);
103macro HAS_DEFINED_PRIVATE(obj, sym) = (!IS_UNDEFINED(obj[sym]));
104macro GET_PRIVATE(obj, sym) = (obj[sym]);
105macro SET_PRIVATE(obj, sym, val) = (obj[sym] = val);
106
107# To avoid ES2015 Function name inference.
108macro ANONYMOUS_FUNCTION(fn) = (0, (fn));
109
110# Constants.  The compiler constant folds them.
111define INFINITY = (1/0);
112define UNDEFINED = (void 0);
113
114# Macros implemented in Python.
115python macro CHAR_CODE(str) = ord(str[1]);
116
117# For messages.js
118# Matches Script::Type from objects.h
119define TYPE_NATIVE = 0;
120define TYPE_EXTENSION = 1;
121define TYPE_NORMAL = 2;
122
123# Matches Script::CompilationType from objects.h
124define COMPILATION_TYPE_HOST = 0;
125define COMPILATION_TYPE_EVAL = 1;
126define COMPILATION_TYPE_JSON = 2;
127
128# Must match PropertyFilter in property-details.h
129define PROPERTY_FILTER_NONE = 0;
130define PROPERTY_FILTER_ONLY_ENUMERABLE = 2;
131define PROPERTY_FILTER_SKIP_STRINGS = 8;
132define PROPERTY_FILTER_SKIP_SYMBOLS = 16;
133
134# Use for keys, values and entries iterators.
135define ITERATOR_KIND_KEYS = 1;
136define ITERATOR_KIND_VALUES = 2;
137define ITERATOR_KIND_ENTRIES = 3;
138
139macro FIXED_ARRAY_GET(array, index) = (%_FixedArrayGet(array, (index) | 0));
140macro FIXED_ARRAY_SET(array, index, value) = (%_FixedArraySet(array, (index) | 0, value));
141# TODO(adamk): Find a more robust way to force Smi representation.
142macro FIXED_ARRAY_SET_SMI(array, index, value) = (FIXED_ARRAY_SET(array, index, (value) | 0));
143
144macro ORDERED_HASH_TABLE_BUCKET_COUNT(table) = (FIXED_ARRAY_GET(table, 0));
145macro ORDERED_HASH_TABLE_ELEMENT_COUNT(table) = (FIXED_ARRAY_GET(table, 1));
146macro ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, count) = (FIXED_ARRAY_SET_SMI(table, 1, count));
147macro ORDERED_HASH_TABLE_DELETED_COUNT(table) = (FIXED_ARRAY_GET(table, 2));
148macro ORDERED_HASH_TABLE_SET_DELETED_COUNT(table, count) = (FIXED_ARRAY_SET_SMI(table, 2, count));
149macro ORDERED_HASH_TABLE_BUCKET_AT(table, bucket) = (FIXED_ARRAY_GET(table, 3 + (bucket)));
150macro ORDERED_HASH_TABLE_SET_BUCKET_AT(table, bucket, entry) = (FIXED_ARRAY_SET(table, 3 + (bucket), entry));
151
152macro ORDERED_HASH_TABLE_HASH_TO_BUCKET(hash, numBuckets) = (hash & ((numBuckets) - 1));
153
154macro ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets) = (3 + (numBuckets) + ((entry) << 1));
155macro ORDERED_HASH_SET_KEY_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets)));
156macro ORDERED_HASH_SET_CHAIN_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets) + 1));
157
158macro ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) = (3 + (numBuckets) + ((entry) * 3));
159macro ORDERED_HASH_MAP_KEY_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets)));
160macro ORDERED_HASH_MAP_VALUE_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) + 1));
161macro ORDERED_HASH_MAP_CHAIN_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) + 2));
162
163# Must match OrderedHashTable::kNotFound.
164define NOT_FOUND = -1;
165
166# Check whether debug is active.
167define DEBUG_IS_ACTIVE = (%_DebugIsActive() != 0);
168
169# UseCounters from include/v8.h
170define kUseAsm = 0;
171define kBreakIterator = 1;
172define kLegacyConst = 2;
173define kMarkDequeOverflow = 3;
174define kStoreBufferOverflow = 4;
175define kSlotsBufferOverflow = 5;
176define kForcedGC = 7;
177define kSloppyMode = 8;
178define kStrictMode = 9;
179define kRegExpPrototypeStickyGetter = 11;
180define kRegExpPrototypeToString = 12;
181define kRegExpPrototypeUnicodeGetter = 13;
182define kIntlV8Parse = 14;
183define kIntlPattern = 15;
184define kIntlResolved = 16;
185define kPromiseChain = 17;
186define kPromiseAccept = 18;
187define kPromiseDefer = 19;
188define kHtmlCommentInExternalScript = 20;
189define kHtmlComment = 21;
190define kSloppyModeBlockScopedFunctionRedefinition = 22;
191define kForInInitializer = 23;
192define kArrayProtectorDirtied = 24;
193define kArraySpeciesModified = 25;
194define kArrayPrototypeConstructorModified = 26;
195define kArrayInstanceProtoModified = 27;
196define kArrayInstanceConstructorModified = 28;
197define kLegacyFunctionDeclaration = 29;
198define kRegExpPrototypeSourceGetter = 30;
199define kRegExpPrototypeOldFlagGetter = 31;
200