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