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