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'); |
| 70 | macro IS_DATE(arg) = (%_IsDate(arg)); |
| 71 | macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error'); |
| 72 | macro IS_FUNCTION(arg) = (%_IsFunction(arg)); |
| 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'); |
| 88 | macro IS_SIMD_VALUE(arg) = (%_IsSimdValue(arg)); |
| 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)); |
| 117 | macro TO_LENGTH_OR_UINT32(arg) = (FLAG_harmony_tolength ? TO_LENGTH(arg) : TO_UINT32(arg)); |
| 118 | macro TO_LENGTH_OR_INTEGER(arg) = (FLAG_harmony_tolength ? TO_LENGTH(arg) : TO_INTEGER(arg)); |
| 119 | macro TO_STRING(arg) = (%_ToString(arg)); |
| 120 | macro TO_NUMBER(arg) = (%_ToNumber(arg)); |
| 121 | macro TO_OBJECT(arg) = (%_ToObject(arg)); |
| 122 | macro TO_PRIMITIVE(arg) = (%_ToPrimitive(arg)); |
| 123 | macro TO_PRIMITIVE_NUMBER(arg) = (%_ToPrimitive_Number(arg)); |
| 124 | macro TO_PRIMITIVE_STRING(arg) = (%_ToPrimitive_String(arg)); |
| 125 | macro TO_NAME(arg) = (%_ToName(arg)); |
| 126 | macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null"); |
| 127 | macro HAS_OWN_PROPERTY(arg, index) = (%_Call(ObjectHasOwnProperty, arg, index)); |
| 128 | macro HAS_INDEX(array, index, is_array) = ((is_array && %_HasFastPackedElements(%IS_VAR(array))) ? (index < array.length) : (index in array)); |
| 129 | |
| 130 | # Private names. |
| 131 | macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym)); |
| 132 | macro HAS_PRIVATE(obj, sym) = (%HasOwnProperty(obj, sym)); |
| 133 | macro HAS_DEFINED_PRIVATE(obj, sym) = (!IS_UNDEFINED(obj[sym])); |
| 134 | macro GET_PRIVATE(obj, sym) = (obj[sym]); |
| 135 | macro SET_PRIVATE(obj, sym, val) = (obj[sym] = val); |
| 136 | |
| 137 | # Constants. The compiler constant folds them. |
| 138 | define INFINITY = (1/0); |
| 139 | define UNDEFINED = (void 0); |
| 140 | |
| 141 | # Macros implemented in Python. |
| 142 | python macro CHAR_CODE(str) = ord(str[1]); |
| 143 | |
| 144 | # Constants used on an array to implement the properties of the RegExp object. |
| 145 | define REGEXP_NUMBER_OF_CAPTURES = 0; |
| 146 | define REGEXP_FIRST_CAPTURE = 3; |
| 147 | |
| 148 | # Macros for internal slot access. |
| 149 | macro REGEXP_GLOBAL(regexp) = (%_RegExpFlags(regexp) & 1); |
| 150 | macro REGEXP_IGNORE_CASE(regexp) = (%_RegExpFlags(regexp) & 2); |
| 151 | macro REGEXP_MULTILINE(regexp) = (%_RegExpFlags(regexp) & 4); |
| 152 | macro REGEXP_STICKY(regexp) = (%_RegExpFlags(regexp) & 8); |
| 153 | macro REGEXP_UNICODE(regexp) = (%_RegExpFlags(regexp) & 16); |
| 154 | macro REGEXP_SOURCE(regexp) = (%_RegExpSource(regexp)); |
| 155 | |
| 156 | # We can't put macros in macros so we use constants here. |
| 157 | # REGEXP_NUMBER_OF_CAPTURES |
| 158 | macro NUMBER_OF_CAPTURES(array) = ((array)[0]); |
| 159 | |
| 160 | # Last input and last subject of regexp matches. |
| 161 | define LAST_SUBJECT_INDEX = 1; |
| 162 | macro LAST_SUBJECT(array) = ((array)[1]); |
| 163 | macro LAST_INPUT(array) = ((array)[2]); |
| 164 | |
| 165 | # REGEXP_FIRST_CAPTURE |
| 166 | macro CAPTURE(index) = (3 + (index)); |
| 167 | define CAPTURE0 = 3; |
| 168 | define CAPTURE1 = 4; |
| 169 | |
| 170 | # For the regexp capture override array. This has the same |
| 171 | # format as the arguments to a function called from |
| 172 | # String.prototype.replace. |
| 173 | macro OVERRIDE_MATCH(override) = ((override)[0]); |
| 174 | macro OVERRIDE_POS(override) = ((override)[(override).length - 2]); |
| 175 | macro OVERRIDE_SUBJECT(override) = ((override)[(override).length - 1]); |
| 176 | # 1-based so index of 1 returns the first capture |
| 177 | macro OVERRIDE_CAPTURE(override, index) = ((override)[(index)]); |
| 178 | |
| 179 | # PropertyDescriptor return value indices - must match |
| 180 | # PropertyDescriptorIndices in runtime-object.cc. |
| 181 | define IS_ACCESSOR_INDEX = 0; |
| 182 | define VALUE_INDEX = 1; |
| 183 | define GETTER_INDEX = 2; |
| 184 | define SETTER_INDEX = 3; |
| 185 | define WRITABLE_INDEX = 4; |
| 186 | define ENUMERABLE_INDEX = 5; |
| 187 | define CONFIGURABLE_INDEX = 6; |
| 188 | |
| 189 | # For messages.js |
| 190 | # Matches Script::Type from objects.h |
| 191 | define TYPE_NATIVE = 0; |
| 192 | define TYPE_EXTENSION = 1; |
| 193 | define TYPE_NORMAL = 2; |
| 194 | |
| 195 | # Matches Script::CompilationType from objects.h |
| 196 | define COMPILATION_TYPE_HOST = 0; |
| 197 | define COMPILATION_TYPE_EVAL = 1; |
| 198 | define COMPILATION_TYPE_JSON = 2; |
| 199 | |
| 200 | # Matches Messages::kNoLineNumberInfo from v8.h |
| 201 | define kNoLineNumberInfo = 0; |
| 202 | |
| 203 | # Must match PropertyFilter in property-details.h |
| 204 | define PROPERTY_FILTER_NONE = 0; |
| 205 | define PROPERTY_FILTER_ONLY_ENUMERABLE = 2; |
| 206 | define PROPERTY_FILTER_SKIP_STRINGS = 8; |
| 207 | define PROPERTY_FILTER_SKIP_SYMBOLS = 16; |
| 208 | |
| 209 | # Use for keys, values and entries iterators. |
| 210 | define ITERATOR_KIND_KEYS = 1; |
| 211 | define ITERATOR_KIND_VALUES = 2; |
| 212 | define ITERATOR_KIND_ENTRIES = 3; |
| 213 | |
| 214 | macro FIXED_ARRAY_GET(array, index) = (%_FixedArrayGet(array, (index) | 0)); |
| 215 | macro FIXED_ARRAY_SET(array, index, value) = (%_FixedArraySet(array, (index) | 0, value)); |
| 216 | # TODO(adamk): Find a more robust way to force Smi representation. |
| 217 | macro FIXED_ARRAY_SET_SMI(array, index, value) = (FIXED_ARRAY_SET(array, index, (value) | 0)); |
| 218 | |
| 219 | macro ORDERED_HASH_TABLE_BUCKET_COUNT(table) = (FIXED_ARRAY_GET(table, 0)); |
| 220 | macro ORDERED_HASH_TABLE_ELEMENT_COUNT(table) = (FIXED_ARRAY_GET(table, 1)); |
| 221 | macro ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, count) = (FIXED_ARRAY_SET_SMI(table, 1, count)); |
| 222 | macro ORDERED_HASH_TABLE_DELETED_COUNT(table) = (FIXED_ARRAY_GET(table, 2)); |
| 223 | macro ORDERED_HASH_TABLE_SET_DELETED_COUNT(table, count) = (FIXED_ARRAY_SET_SMI(table, 2, count)); |
| 224 | macro ORDERED_HASH_TABLE_BUCKET_AT(table, bucket) = (FIXED_ARRAY_GET(table, 3 + (bucket))); |
| 225 | macro ORDERED_HASH_TABLE_SET_BUCKET_AT(table, bucket, entry) = (FIXED_ARRAY_SET(table, 3 + (bucket), entry)); |
| 226 | |
| 227 | macro ORDERED_HASH_TABLE_HASH_TO_BUCKET(hash, numBuckets) = (hash & ((numBuckets) - 1)); |
| 228 | |
| 229 | macro ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets) = (3 + (numBuckets) + ((entry) << 1)); |
| 230 | macro ORDERED_HASH_SET_KEY_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets))); |
| 231 | macro ORDERED_HASH_SET_CHAIN_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets) + 1)); |
| 232 | |
| 233 | macro ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) = (3 + (numBuckets) + ((entry) * 3)); |
| 234 | macro ORDERED_HASH_MAP_KEY_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets))); |
| 235 | macro ORDERED_HASH_MAP_VALUE_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) + 1)); |
| 236 | macro ORDERED_HASH_MAP_CHAIN_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) + 2)); |
| 237 | |
| 238 | # Must match OrderedHashTable::kNotFound. |
| 239 | define NOT_FOUND = -1; |
| 240 | |
| 241 | # Check whether debug is active. |
| 242 | define DEBUG_IS_ACTIVE = (%_DebugIsActive() != 0); |
| 243 | macro DEBUG_PREPARE_STEP_IN_IF_STEPPING(function) = if (%_DebugIsActive() != 0) %DebugPrepareStepInIfStepping(function); |
| 244 | |
| 245 | # SharedFlag equivalents |
| 246 | define kNotShared = false; |
| 247 | define kShared = true; |
| 248 | |
| 249 | # UseCounters from include/v8.h |
| 250 | define kUseAsm = 0; |
| 251 | define kBreakIterator = 1; |
| 252 | define kLegacyConst = 2; |
| 253 | define kMarkDequeOverflow = 3; |
| 254 | define kStoreBufferOverflow = 4; |
| 255 | define kSlotsBufferOverflow = 5; |
| 256 | define kObjectObserve = 6; |
| 257 | define kForcedGC = 7; |
| 258 | define kSloppyMode = 8; |
| 259 | define kStrictMode = 9; |
| 260 | define kStrongMode = 10; |
| 261 | define kRegExpPrototypeStickyGetter = 11; |
| 262 | define kRegExpPrototypeToString = 12; |
| 263 | define kRegExpPrototypeUnicodeGetter = 13; |
| 264 | define kIntlV8Parse = 14; |
| 265 | define kIntlPattern = 15; |
| 266 | define kIntlResolved = 16; |
| 267 | define kPromiseChain = 17; |
| 268 | define kPromiseAccept = 18; |
| 269 | define kPromiseDefer = 19; |