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 31const NONE = 0; 32const READ_ONLY = 1; 33const DONT_ENUM = 2; 34const DONT_DELETE = 4; 35const NEW_ONE_BYTE_STRING = true; 36const NEW_TWO_BYTE_STRING = false; 37 38# Constants used for getter and setter operations. 39const GETTER = 0; 40const SETTER = 1; 41 42# These definitions must match the index of the properties in objects.h. 43const kApiTagOffset = 0; 44const kApiPropertyListOffset = 1; 45const kApiSerialNumberOffset = 3; 46const kApiConstructorOffset = 3; 47const kApiPrototypeTemplateOffset = 5; 48const kApiParentTemplateOffset = 6; 49const kApiFlagOffset = 14; 50 51const NO_HINT = 0; 52const NUMBER_HINT = 1; 53const STRING_HINT = 2; 54 55const kFunctionTag = 0; 56const kNewObjectTag = 1; 57 58# For date.js. 59const HoursPerDay = 24; 60const MinutesPerHour = 60; 61const SecondsPerMinute = 60; 62const msPerSecond = 1000; 63const msPerMinute = 60000; 64const msPerHour = 3600000; 65const msPerDay = 86400000; 66const msPerMonth = 2592000000; 67 68# For apinatives.js 69const kUninitialized = -1; 70const kReadOnlyPrototypeBit = 3; 71const kRemovePrototypeBit = 4; # For FunctionTemplateInfo, matches objects.h 72const kDoNotCacheBit = 5; # For FunctionTemplateInfo, matches objects.h 73 74# Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1). 75const kInvalidDate = 'Invalid Date'; 76const kDayZeroInJulianDay = 2440588; 77const kMonthMask = 0x1e0; 78const kDayMask = 0x01f; 79const kYearShift = 9; 80const kMonthShift = 5; 81 82# Limits for parts of the date, so that we support all the dates that 83# ECMA 262 - 15.9.1.1 requires us to, but at the same time be sure that 84# the date (days since 1970) is in SMI range. 85const kMinYear = -1000000; 86const kMaxYear = 1000000; 87const kMinMonth = -10000000; 88const kMaxMonth = 10000000; 89 90# Strict mode flags for passing to %SetProperty 91const kSloppyMode = 0; 92const kStrictMode = 1; 93 94# Native cache ids. 95const STRING_TO_REGEXP_CACHE_ID = 0; 96 97# Type query macros. 98# 99# Note: We have special support for typeof(foo) === 'bar' in the compiler. 100# It will *not* generate a runtime typeof call for the most important 101# values of 'bar'. 102macro IS_NULL(arg) = (arg === null); 103macro IS_NULL_OR_UNDEFINED(arg) = (arg == null); 104macro IS_UNDEFINED(arg) = (arg === (void 0)); 105macro IS_NUMBER(arg) = (typeof(arg) === 'number'); 106macro IS_STRING(arg) = (typeof(arg) === 'string'); 107macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean'); 108macro IS_SYMBOL(arg) = (typeof(arg) === 'symbol'); 109macro IS_OBJECT(arg) = (%_IsObject(arg)); 110macro IS_ARRAY(arg) = (%_IsArray(arg)); 111macro IS_FUNCTION(arg) = (%_IsFunction(arg)); 112macro IS_REGEXP(arg) = (%_IsRegExp(arg)); 113macro IS_SET(arg) = (%_ClassOf(arg) === 'Set'); 114macro IS_MAP(arg) = (%_ClassOf(arg) === 'Map'); 115macro IS_WEAKMAP(arg) = (%_ClassOf(arg) === 'WeakMap'); 116macro IS_WEAKSET(arg) = (%_ClassOf(arg) === 'WeakSet'); 117macro IS_DATE(arg) = (%_ClassOf(arg) === 'Date'); 118macro IS_NUMBER_WRAPPER(arg) = (%_ClassOf(arg) === 'Number'); 119macro IS_STRING_WRAPPER(arg) = (%_ClassOf(arg) === 'String'); 120macro IS_SYMBOL_WRAPPER(arg) = (%_ClassOf(arg) === 'Symbol'); 121macro IS_BOOLEAN_WRAPPER(arg) = (%_ClassOf(arg) === 'Boolean'); 122macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error'); 123macro IS_SCRIPT(arg) = (%_ClassOf(arg) === 'Script'); 124macro IS_ARGUMENTS(arg) = (%_ClassOf(arg) === 'Arguments'); 125macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global'); 126macro IS_ARRAYBUFFER(arg) = (%_ClassOf(arg) === 'ArrayBuffer'); 127macro IS_DATAVIEW(arg) = (%_ClassOf(arg) === 'DataView'); 128macro IS_GENERATOR(arg) = (%_ClassOf(arg) === 'Generator'); 129macro IS_SET_ITERATOR(arg) = (%_ClassOf(arg) === 'Set Iterator'); 130macro IS_MAP_ITERATOR(arg) = (%_ClassOf(arg) === 'Map Iterator'); 131macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg)); 132macro FLOOR(arg) = $floor(arg); 133 134# Macro for ECMAScript 5 queries of the type: 135# "Type(O) is object." 136# This is the same as being either a function or an object in V8 terminology 137# (including proxies). 138# In addition, an undetectable object is also included by this. 139macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg)); 140 141# Macro for ECMAScript 5 queries of the type: 142# "IsCallable(O)" 143# We assume here that this is the same as being either a function or a function 144# proxy. That ignores host objects with [[Call]] methods, but in most situations 145# we cannot handle those anyway. 146macro IS_SPEC_FUNCTION(arg) = (%_ClassOf(arg) === 'Function'); 147 148# Macro for ES6 CheckObjectCoercible 149# Will throw a TypeError of the form "[functionName] called on null or undefined". 150macro CHECK_OBJECT_COERCIBLE(arg, functionName) = if (IS_NULL_OR_UNDEFINED(arg) && !IS_UNDETECTABLE(arg)) throw MakeTypeError('called_on_null_or_undefined', [functionName]); 151 152# Indices in bound function info retrieved by %BoundFunctionGetBindings(...). 153const kBoundFunctionIndex = 0; 154const kBoundThisIndex = 1; 155const kBoundArgumentsStartIndex = 2; 156 157# Inline macros. Use %IS_VAR to make sure arg is evaluated only once. 158macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg)); 159macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0))); 160macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg))); 161macro TO_INTEGER_FOR_SIDE_EFFECT(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToNumber(arg)); 162macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg))); 163macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0)); 164macro TO_UINT32(arg) = (arg >>> 0); 165macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg)); 166macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : NonNumberToNumber(arg)); 167macro TO_OBJECT_INLINE(arg) = (IS_SPEC_OBJECT(%IS_VAR(arg)) ? arg : ToObject(arg)); 168macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null"); 169 170# Private names. 171# GET_PRIVATE should only be used if the property is known to exists on obj 172# itself (it should really use %GetOwnProperty, but that would be way slower). 173macro GLOBAL_PRIVATE(name) = (%CreateGlobalPrivateSymbol(name)); 174macro NEW_PRIVATE(name) = (%CreatePrivateSymbol(name)); 175macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym)); 176macro HAS_PRIVATE(obj, sym) = (%HasOwnProperty(obj, sym)); 177macro GET_PRIVATE(obj, sym) = (obj[sym]); 178macro SET_PRIVATE(obj, sym, val) = (obj[sym] = val); 179macro DELETE_PRIVATE(obj, sym) = (delete obj[sym]); 180 181# Constants. The compiler constant folds them. 182const NAN = $NaN; 183const INFINITY = (1/0); 184const UNDEFINED = (void 0); 185 186# Macros implemented in Python. 187python macro CHAR_CODE(str) = ord(str[1]); 188 189# Constants used on an array to implement the properties of the RegExp object. 190const REGEXP_NUMBER_OF_CAPTURES = 0; 191const REGEXP_FIRST_CAPTURE = 3; 192 193# We can't put macros in macros so we use constants here. 194# REGEXP_NUMBER_OF_CAPTURES 195macro NUMBER_OF_CAPTURES(array) = ((array)[0]); 196 197# Limit according to ECMA 262 15.9.1.1 198const MAX_TIME_MS = 8640000000000000; 199# Limit which is MAX_TIME_MS + msPerMonth. 200const MAX_TIME_BEFORE_UTC = 8640002592000000; 201 202# Gets the value of a Date object. If arg is not a Date object 203# a type error is thrown. 204macro CHECK_DATE(arg) = if (%_ClassOf(arg) !== 'Date') ThrowDateTypeError(); 205macro LOCAL_DATE_VALUE(arg) = (%_DateField(arg, 0) + %_DateField(arg, 21)); 206macro UTC_DATE_VALUE(arg) = (%_DateField(arg, 0)); 207 208macro LOCAL_YEAR(arg) = (%_DateField(arg, 1)); 209macro LOCAL_MONTH(arg) = (%_DateField(arg, 2)); 210macro LOCAL_DAY(arg) = (%_DateField(arg, 3)); 211macro LOCAL_WEEKDAY(arg) = (%_DateField(arg, 4)); 212macro LOCAL_HOUR(arg) = (%_DateField(arg, 5)); 213macro LOCAL_MIN(arg) = (%_DateField(arg, 6)); 214macro LOCAL_SEC(arg) = (%_DateField(arg, 7)); 215macro LOCAL_MS(arg) = (%_DateField(arg, 8)); 216macro LOCAL_DAYS(arg) = (%_DateField(arg, 9)); 217macro LOCAL_TIME_IN_DAY(arg) = (%_DateField(arg, 10)); 218 219macro UTC_YEAR(arg) = (%_DateField(arg, 11)); 220macro UTC_MONTH(arg) = (%_DateField(arg, 12)); 221macro UTC_DAY(arg) = (%_DateField(arg, 13)); 222macro UTC_WEEKDAY(arg) = (%_DateField(arg, 14)); 223macro UTC_HOUR(arg) = (%_DateField(arg, 15)); 224macro UTC_MIN(arg) = (%_DateField(arg, 16)); 225macro UTC_SEC(arg) = (%_DateField(arg, 17)); 226macro UTC_MS(arg) = (%_DateField(arg, 18)); 227macro UTC_DAYS(arg) = (%_DateField(arg, 19)); 228macro UTC_TIME_IN_DAY(arg) = (%_DateField(arg, 20)); 229 230macro TIMEZONE_OFFSET(arg) = (%_DateField(arg, 21)); 231 232macro SET_UTC_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 1)); 233macro SET_LOCAL_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 0)); 234 235# Last input and last subject of regexp matches. 236const LAST_SUBJECT_INDEX = 1; 237macro LAST_SUBJECT(array) = ((array)[1]); 238macro LAST_INPUT(array) = ((array)[2]); 239 240# REGEXP_FIRST_CAPTURE 241macro CAPTURE(index) = (3 + (index)); 242const CAPTURE0 = 3; 243const CAPTURE1 = 4; 244 245# For the regexp capture override array. This has the same 246# format as the arguments to a function called from 247# String.prototype.replace. 248macro OVERRIDE_MATCH(override) = ((override)[0]); 249macro OVERRIDE_POS(override) = ((override)[(override).length - 2]); 250macro OVERRIDE_SUBJECT(override) = ((override)[(override).length - 1]); 251# 1-based so index of 1 returns the first capture 252macro OVERRIDE_CAPTURE(override, index) = ((override)[(index)]); 253 254# PropertyDescriptor return value indices - must match 255# PropertyDescriptorIndices in runtime.cc. 256const IS_ACCESSOR_INDEX = 0; 257const VALUE_INDEX = 1; 258const GETTER_INDEX = 2; 259const SETTER_INDEX = 3; 260const WRITABLE_INDEX = 4; 261const ENUMERABLE_INDEX = 5; 262const CONFIGURABLE_INDEX = 6; 263 264# For messages.js 265# Matches Script::Type from objects.h 266const TYPE_NATIVE = 0; 267const TYPE_EXTENSION = 1; 268const TYPE_NORMAL = 2; 269 270# Matches Script::CompilationType from objects.h 271const COMPILATION_TYPE_HOST = 0; 272const COMPILATION_TYPE_EVAL = 1; 273const COMPILATION_TYPE_JSON = 2; 274 275# Matches Messages::kNoLineNumberInfo from v8.h 276const kNoLineNumberInfo = 0; 277 278# Matches PropertyAttributes from property-details.h 279const PROPERTY_ATTRIBUTES_NONE = 0; 280const PROPERTY_ATTRIBUTES_STRING = 8; 281const PROPERTY_ATTRIBUTES_SYMBOLIC = 16; 282const PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL = 32; 283 284# Use for keys, values and entries iterators. 285const ITERATOR_KIND_KEYS = 1; 286const ITERATOR_KIND_VALUES = 2; 287const ITERATOR_KIND_ENTRIES = 3; 288