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