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