| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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 | # Safe maximum number of arguments to push to stack, when multiplied by | 
|  | 43 | # pointer size. Used by Function.prototype.apply(), Reflect.apply() and | 
|  | 44 | # Reflect.construct(). | 
|  | 45 | define kSafeArgumentsLength = 0x800000; | 
|  | 46 |  | 
|  | 47 | # 2^53 - 1 | 
|  | 48 | define kMaxSafeInteger = 9007199254740991; | 
|  | 49 |  | 
|  | 50 | # 2^32 - 1 | 
|  | 51 | define kMaxUint32 = 4294967295; | 
|  | 52 |  | 
|  | 53 | # Strict mode flags for passing to %SetProperty | 
|  | 54 | define kSloppyMode = 0; | 
|  | 55 | define kStrictMode = 1; | 
|  | 56 |  | 
|  | 57 | # Native cache ids. | 
|  | 58 | define STRING_TO_REGEXP_CACHE_ID = 0; | 
|  | 59 |  | 
|  | 60 | # Type query macros. | 
|  | 61 | # | 
|  | 62 | # Note: We have special support for typeof(foo) === 'bar' in the compiler. | 
|  | 63 | #       It will *not* generate a runtime typeof call for the most important | 
|  | 64 | #       values of 'bar'. | 
|  | 65 | macro IS_ARRAY(arg)             = (%_IsArray(arg)); | 
|  | 66 | macro IS_ARRAYBUFFER(arg)       = (%_ClassOf(arg) === 'ArrayBuffer'); | 
|  | 67 | macro IS_BOOLEAN(arg)           = (typeof(arg) === 'boolean'); | 
|  | 68 | macro IS_BOOLEAN_WRAPPER(arg)   = (%_ClassOf(arg) === 'Boolean'); | 
|  | 69 | macro IS_DATAVIEW(arg)          = (%_ClassOf(arg) === 'DataView'); | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 70 | macro IS_DATE(arg)              = (%IsDate(arg)); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 71 | macro IS_ERROR(arg)             = (%_ClassOf(arg) === 'Error'); | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 72 | macro IS_FUNCTION(arg)          = (%IsFunction(arg)); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 73 | macro IS_GENERATOR(arg)         = (%_ClassOf(arg) === 'Generator'); | 
|  | 74 | macro IS_GLOBAL(arg)            = (%_ClassOf(arg) === 'global'); | 
|  | 75 | macro IS_MAP(arg)               = (%_ClassOf(arg) === 'Map'); | 
|  | 76 | macro IS_MAP_ITERATOR(arg)      = (%_ClassOf(arg) === 'Map Iterator'); | 
|  | 77 | macro IS_NULL(arg)              = (arg === null); | 
|  | 78 | macro IS_NULL_OR_UNDEFINED(arg) = (arg == null); | 
|  | 79 | macro IS_NUMBER(arg)            = (typeof(arg) === 'number'); | 
|  | 80 | macro IS_NUMBER_WRAPPER(arg)    = (%_ClassOf(arg) === 'Number'); | 
|  | 81 | macro IS_OBJECT(arg)            = (typeof(arg) === 'object'); | 
|  | 82 | macro IS_PROXY(arg)             = (%_IsJSProxy(arg)); | 
|  | 83 | macro IS_REGEXP(arg)            = (%_IsRegExp(arg)); | 
|  | 84 | macro IS_SCRIPT(arg)            = (%_ClassOf(arg) === 'Script'); | 
|  | 85 | macro IS_SET(arg)               = (%_ClassOf(arg) === 'Set'); | 
|  | 86 | macro IS_SET_ITERATOR(arg)      = (%_ClassOf(arg) === 'Set Iterator'); | 
|  | 87 | macro IS_SHAREDARRAYBUFFER(arg) = (%_ClassOf(arg) === 'SharedArrayBuffer'); | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 88 | macro IS_SIMD_VALUE(arg)        = (%IsSimdValue(arg)); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 89 | macro IS_STRING(arg)            = (typeof(arg) === 'string'); | 
|  | 90 | macro IS_STRING_WRAPPER(arg)    = (%_ClassOf(arg) === 'String'); | 
|  | 91 | macro IS_STRONG(arg)            = (%IsStrong(arg)); | 
|  | 92 | macro IS_SYMBOL(arg)            = (typeof(arg) === 'symbol'); | 
|  | 93 | macro IS_SYMBOL_WRAPPER(arg)    = (%_ClassOf(arg) === 'Symbol'); | 
|  | 94 | macro IS_UNDEFINED(arg)         = (arg === (void 0)); | 
|  | 95 | macro IS_WEAKMAP(arg)           = (%_ClassOf(arg) === 'WeakMap'); | 
|  | 96 | macro IS_WEAKSET(arg)           = (%_ClassOf(arg) === 'WeakSet'); | 
|  | 97 |  | 
|  | 98 | # Macro for ES queries of the type: "Type(O) is Object." | 
|  | 99 | macro IS_RECEIVER(arg) = (%_IsJSReceiver(arg)); | 
|  | 100 |  | 
|  | 101 | # Macro for ES queries of the type: "IsCallable(O)" | 
|  | 102 | macro IS_CALLABLE(arg) = (typeof(arg) === 'function'); | 
|  | 103 |  | 
|  | 104 | # Macro for ES6 CheckObjectCoercible | 
|  | 105 | # Will throw a TypeError of the form "[functionName] called on null or undefined". | 
|  | 106 | macro CHECK_OBJECT_COERCIBLE(arg, functionName) = if (IS_NULL(%IS_VAR(arg)) || IS_UNDEFINED(arg)) throw MakeTypeError(kCalledOnNullOrUndefined, functionName); | 
|  | 107 |  | 
|  | 108 | # Inline macros. Use %IS_VAR to make sure arg is evaluated only once. | 
|  | 109 | macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg)); | 
|  | 110 | macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0))); | 
|  | 111 | macro TO_BOOLEAN(arg) = (!!(arg)); | 
|  | 112 | macro TO_INTEGER(arg) = (%_ToInteger(arg)); | 
|  | 113 | macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(arg)); | 
|  | 114 | macro TO_INT32(arg) = ((arg) | 0); | 
|  | 115 | macro TO_UINT32(arg) = ((arg) >>> 0); | 
|  | 116 | macro TO_LENGTH(arg) = (%_ToLength(arg)); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 117 | macro TO_STRING(arg) = (%_ToString(arg)); | 
|  | 118 | macro TO_NUMBER(arg) = (%_ToNumber(arg)); | 
|  | 119 | macro TO_OBJECT(arg) = (%_ToObject(arg)); | 
|  | 120 | macro TO_PRIMITIVE(arg) = (%_ToPrimitive(arg)); | 
|  | 121 | macro TO_PRIMITIVE_NUMBER(arg) = (%_ToPrimitive_Number(arg)); | 
|  | 122 | macro TO_PRIMITIVE_STRING(arg) = (%_ToPrimitive_String(arg)); | 
|  | 123 | macro TO_NAME(arg) = (%_ToName(arg)); | 
|  | 124 | macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null"); | 
|  | 125 | macro HAS_OWN_PROPERTY(arg, index) = (%_Call(ObjectHasOwnProperty, arg, index)); | 
|  | 126 | macro HAS_INDEX(array, index, is_array) = ((is_array && %_HasFastPackedElements(%IS_VAR(array))) ? (index < array.length) : (index in array)); | 
|  | 127 |  | 
|  | 128 | # Private names. | 
|  | 129 | macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym)); | 
|  | 130 | macro HAS_PRIVATE(obj, sym) = (%HasOwnProperty(obj, sym)); | 
|  | 131 | macro HAS_DEFINED_PRIVATE(obj, sym) = (!IS_UNDEFINED(obj[sym])); | 
|  | 132 | macro GET_PRIVATE(obj, sym) = (obj[sym]); | 
|  | 133 | macro SET_PRIVATE(obj, sym, val) = (obj[sym] = val); | 
|  | 134 |  | 
|  | 135 | # Constants.  The compiler constant folds them. | 
|  | 136 | define INFINITY = (1/0); | 
|  | 137 | define UNDEFINED = (void 0); | 
|  | 138 |  | 
|  | 139 | # Macros implemented in Python. | 
|  | 140 | python macro CHAR_CODE(str) = ord(str[1]); | 
|  | 141 |  | 
|  | 142 | # Constants used on an array to implement the properties of the RegExp object. | 
|  | 143 | define REGEXP_NUMBER_OF_CAPTURES = 0; | 
|  | 144 | define REGEXP_FIRST_CAPTURE = 3; | 
|  | 145 |  | 
|  | 146 | # Macros for internal slot access. | 
|  | 147 | macro REGEXP_GLOBAL(regexp) = (%_RegExpFlags(regexp) & 1); | 
|  | 148 | macro REGEXP_IGNORE_CASE(regexp) = (%_RegExpFlags(regexp) & 2); | 
|  | 149 | macro REGEXP_MULTILINE(regexp) = (%_RegExpFlags(regexp) & 4); | 
|  | 150 | macro REGEXP_STICKY(regexp) = (%_RegExpFlags(regexp) & 8); | 
|  | 151 | macro REGEXP_UNICODE(regexp) = (%_RegExpFlags(regexp) & 16); | 
|  | 152 | macro REGEXP_SOURCE(regexp) = (%_RegExpSource(regexp)); | 
|  | 153 |  | 
|  | 154 | # We can't put macros in macros so we use constants here. | 
|  | 155 | # REGEXP_NUMBER_OF_CAPTURES | 
|  | 156 | macro NUMBER_OF_CAPTURES(array) = ((array)[0]); | 
|  | 157 |  | 
|  | 158 | # Last input and last subject of regexp matches. | 
|  | 159 | define LAST_SUBJECT_INDEX = 1; | 
|  | 160 | macro LAST_SUBJECT(array) = ((array)[1]); | 
|  | 161 | macro LAST_INPUT(array) = ((array)[2]); | 
|  | 162 |  | 
|  | 163 | # REGEXP_FIRST_CAPTURE | 
|  | 164 | macro CAPTURE(index) = (3 + (index)); | 
|  | 165 | define CAPTURE0 = 3; | 
|  | 166 | define CAPTURE1 = 4; | 
|  | 167 |  | 
|  | 168 | # For the regexp capture override array.  This has the same | 
|  | 169 | # format as the arguments to a function called from | 
|  | 170 | # String.prototype.replace. | 
|  | 171 | macro OVERRIDE_MATCH(override) = ((override)[0]); | 
|  | 172 | macro OVERRIDE_POS(override) = ((override)[(override).length - 2]); | 
|  | 173 | macro OVERRIDE_SUBJECT(override) = ((override)[(override).length - 1]); | 
|  | 174 | # 1-based so index of 1 returns the first capture | 
|  | 175 | macro OVERRIDE_CAPTURE(override, index) = ((override)[(index)]); | 
|  | 176 |  | 
|  | 177 | # PropertyDescriptor return value indices - must match | 
|  | 178 | # PropertyDescriptorIndices in runtime-object.cc. | 
|  | 179 | define IS_ACCESSOR_INDEX = 0; | 
|  | 180 | define VALUE_INDEX = 1; | 
|  | 181 | define GETTER_INDEX = 2; | 
|  | 182 | define SETTER_INDEX = 3; | 
|  | 183 | define WRITABLE_INDEX = 4; | 
|  | 184 | define ENUMERABLE_INDEX = 5; | 
|  | 185 | define CONFIGURABLE_INDEX = 6; | 
|  | 186 |  | 
|  | 187 | # For messages.js | 
|  | 188 | # Matches Script::Type from objects.h | 
|  | 189 | define TYPE_NATIVE = 0; | 
|  | 190 | define TYPE_EXTENSION = 1; | 
|  | 191 | define TYPE_NORMAL = 2; | 
|  | 192 |  | 
|  | 193 | # Matches Script::CompilationType from objects.h | 
|  | 194 | define COMPILATION_TYPE_HOST = 0; | 
|  | 195 | define COMPILATION_TYPE_EVAL = 1; | 
|  | 196 | define COMPILATION_TYPE_JSON = 2; | 
|  | 197 |  | 
|  | 198 | # Matches Messages::kNoLineNumberInfo from v8.h | 
|  | 199 | define kNoLineNumberInfo = 0; | 
|  | 200 |  | 
|  | 201 | # Must match PropertyFilter in property-details.h | 
|  | 202 | define PROPERTY_FILTER_NONE = 0; | 
|  | 203 | define PROPERTY_FILTER_ONLY_ENUMERABLE = 2; | 
|  | 204 | define PROPERTY_FILTER_SKIP_STRINGS = 8; | 
|  | 205 | define PROPERTY_FILTER_SKIP_SYMBOLS = 16; | 
|  | 206 |  | 
|  | 207 | # Use for keys, values and entries iterators. | 
|  | 208 | define ITERATOR_KIND_KEYS = 1; | 
|  | 209 | define ITERATOR_KIND_VALUES = 2; | 
|  | 210 | define ITERATOR_KIND_ENTRIES = 3; | 
|  | 211 |  | 
|  | 212 | macro FIXED_ARRAY_GET(array, index) = (%_FixedArrayGet(array, (index) | 0)); | 
|  | 213 | macro FIXED_ARRAY_SET(array, index, value) = (%_FixedArraySet(array, (index) | 0, value)); | 
|  | 214 | # TODO(adamk): Find a more robust way to force Smi representation. | 
|  | 215 | macro FIXED_ARRAY_SET_SMI(array, index, value) = (FIXED_ARRAY_SET(array, index, (value) | 0)); | 
|  | 216 |  | 
|  | 217 | macro ORDERED_HASH_TABLE_BUCKET_COUNT(table) = (FIXED_ARRAY_GET(table, 0)); | 
|  | 218 | macro ORDERED_HASH_TABLE_ELEMENT_COUNT(table) = (FIXED_ARRAY_GET(table, 1)); | 
|  | 219 | macro ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, count) = (FIXED_ARRAY_SET_SMI(table, 1, count)); | 
|  | 220 | macro ORDERED_HASH_TABLE_DELETED_COUNT(table) = (FIXED_ARRAY_GET(table, 2)); | 
|  | 221 | macro ORDERED_HASH_TABLE_SET_DELETED_COUNT(table, count) = (FIXED_ARRAY_SET_SMI(table, 2, count)); | 
|  | 222 | macro ORDERED_HASH_TABLE_BUCKET_AT(table, bucket) = (FIXED_ARRAY_GET(table, 3 + (bucket))); | 
|  | 223 | macro ORDERED_HASH_TABLE_SET_BUCKET_AT(table, bucket, entry) = (FIXED_ARRAY_SET(table, 3 + (bucket), entry)); | 
|  | 224 |  | 
|  | 225 | macro ORDERED_HASH_TABLE_HASH_TO_BUCKET(hash, numBuckets) = (hash & ((numBuckets) - 1)); | 
|  | 226 |  | 
|  | 227 | macro ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets) = (3 + (numBuckets) + ((entry) << 1)); | 
|  | 228 | macro ORDERED_HASH_SET_KEY_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets))); | 
|  | 229 | macro ORDERED_HASH_SET_CHAIN_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets) + 1)); | 
|  | 230 |  | 
|  | 231 | macro ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) = (3 + (numBuckets) + ((entry) * 3)); | 
|  | 232 | macro ORDERED_HASH_MAP_KEY_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets))); | 
|  | 233 | macro ORDERED_HASH_MAP_VALUE_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) + 1)); | 
|  | 234 | macro ORDERED_HASH_MAP_CHAIN_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) + 2)); | 
|  | 235 |  | 
|  | 236 | # Must match OrderedHashTable::kNotFound. | 
|  | 237 | define NOT_FOUND = -1; | 
|  | 238 |  | 
|  | 239 | # Check whether debug is active. | 
|  | 240 | define DEBUG_IS_ACTIVE = (%_DebugIsActive() != 0); | 
|  | 241 | macro DEBUG_PREPARE_STEP_IN_IF_STEPPING(function) = if (%_DebugIsActive() != 0) %DebugPrepareStepInIfStepping(function); | 
|  | 242 |  | 
|  | 243 | # SharedFlag equivalents | 
|  | 244 | define kNotShared = false; | 
|  | 245 | define kShared = true; | 
|  | 246 |  | 
|  | 247 | # UseCounters from include/v8.h | 
|  | 248 | define kUseAsm = 0; | 
|  | 249 | define kBreakIterator = 1; | 
|  | 250 | define kLegacyConst = 2; | 
|  | 251 | define kMarkDequeOverflow = 3; | 
|  | 252 | define kStoreBufferOverflow = 4; | 
|  | 253 | define kSlotsBufferOverflow = 5; | 
|  | 254 | define kObjectObserve = 6; | 
|  | 255 | define kForcedGC = 7; | 
|  | 256 | define kSloppyMode = 8; | 
|  | 257 | define kStrictMode = 9; | 
|  | 258 | define kStrongMode = 10; | 
|  | 259 | define kRegExpPrototypeStickyGetter = 11; | 
|  | 260 | define kRegExpPrototypeToString = 12; | 
|  | 261 | define kRegExpPrototypeUnicodeGetter = 13; | 
|  | 262 | define kIntlV8Parse = 14; | 
|  | 263 | define kIntlPattern = 15; | 
|  | 264 | define kIntlResolved = 16; | 
|  | 265 | define kPromiseChain = 17; | 
|  | 266 | define kPromiseAccept = 18; | 
|  | 267 | define kPromiseDefer = 19; |