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 const NONE = 0; 32 const READ_ONLY = 1; 33 const DONT_ENUM = 2; 34 const DONT_DELETE = 4; 35 36 # Constants used for getter and setter operations. 37 const GETTER = 0; 38 const SETTER = 1; 39 40 # These definitions must match the index of the properties in objects.h. 41 const kApiTagOffset = 0; 42 const kApiPropertyListOffset = 1; 43 const kApiSerialNumberOffset = 2; 44 const kApiConstructorOffset = 2; 45 const kApiPrototypeTemplateOffset = 5; 46 const kApiParentTemplateOffset = 6; 47 const kApiFlagOffset = 14; 48 49 const NO_HINT = 0; 50 const NUMBER_HINT = 1; 51 const STRING_HINT = 2; 52 53 const kFunctionTag = 0; 54 const kNewObjectTag = 1; 55 56 # For date.js. 57 const HoursPerDay = 24; 58 const MinutesPerHour = 60; 59 const SecondsPerMinute = 60; 60 const msPerSecond = 1000; 61 const msPerMinute = 60000; 62 const msPerHour = 3600000; 63 const msPerDay = 86400000; 64 const msPerMonth = 2592000000; 65 66 # For apinatives.js 67 const kUninitialized = -1; 68 const kReadOnlyPrototypeBit = 3; # For FunctionTemplateInfo, matches objects.h 69 70 # Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1). 71 const kInvalidDate = 'Invalid Date'; 72 const kDayZeroInJulianDay = 2440588; 73 const kMonthMask = 0x1e0; 74 const kDayMask = 0x01f; 75 const kYearShift = 9; 76 const kMonthShift = 5; 77 78 # Limits for parts of the date, so that we support all the dates that 79 # ECMA 262 - 15.9.1.1 requires us to, but at the same time be sure that 80 # the date (days since 1970) is in SMI range. 81 const kMinYear = -1000000; 82 const kMaxYear = 1000000; 83 const kMinMonth = -10000000; 84 const kMaxMonth = 10000000; 85 86 # Native cache ids. 87 const STRING_TO_REGEXP_CACHE_ID = 0; 88 89 # Type query macros. 90 # 91 # Note: We have special support for typeof(foo) === 'bar' in the compiler. 92 # It will *not* generate a runtime typeof call for the most important 93 # values of 'bar'. 94 macro IS_NULL(arg) = (arg === null); 95 macro IS_NULL_OR_UNDEFINED(arg) = (arg == null); 96 macro IS_UNDEFINED(arg) = (typeof(arg) === 'undefined'); 97 macro IS_NUMBER(arg) = (typeof(arg) === 'number'); 98 macro IS_STRING(arg) = (typeof(arg) === 'string'); 99 macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean'); 100 macro IS_OBJECT(arg) = (%_IsObject(arg)); 101 macro IS_ARRAY(arg) = (%_IsArray(arg)); 102 macro IS_FUNCTION(arg) = (%_IsFunction(arg)); 103 macro IS_REGEXP(arg) = (%_IsRegExp(arg)); 104 macro IS_SET(arg) = (%_ClassOf(arg) === 'Set'); 105 macro IS_MAP(arg) = (%_ClassOf(arg) === 'Map'); 106 macro IS_WEAKMAP(arg) = (%_ClassOf(arg) === 'WeakMap'); 107 macro IS_DATE(arg) = (%_ClassOf(arg) === 'Date'); 108 macro IS_NUMBER_WRAPPER(arg) = (%_ClassOf(arg) === 'Number'); 109 macro IS_STRING_WRAPPER(arg) = (%_ClassOf(arg) === 'String'); 110 macro IS_BOOLEAN_WRAPPER(arg) = (%_ClassOf(arg) === 'Boolean'); 111 macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error'); 112 macro IS_SCRIPT(arg) = (%_ClassOf(arg) === 'Script'); 113 macro IS_ARGUMENTS(arg) = (%_ClassOf(arg) === 'Arguments'); 114 macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global'); 115 macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg)); 116 macro FLOOR(arg) = $floor(arg); 117 118 # Macro for ECMAScript 5 queries of the type: 119 # "Type(O) is object." 120 # This is the same as being either a function or an object in V8 terminology 121 # (including proxies). 122 # In addition, an undetectable object is also included by this. 123 macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg)); 124 125 # Macro for ECMAScript 5 queries of the type: 126 # "IsCallable(O)" 127 # We assume here that this is the same as being either a function or a function 128 # proxy. That ignores host objects with [[Call]] methods, but in most situations 129 # we cannot handle those anyway. 130 macro IS_SPEC_FUNCTION(arg) = (%_ClassOf(arg) === 'Function'); 131 132 # Indices in bound function info retrieved by %BoundFunctionGetBindings(...). 133 const kBoundFunctionIndex = 0; 134 const kBoundThisIndex = 1; 135 const kBoundArgumentsStartIndex = 2; 136 137 # Inline macros. Use %IS_VAR to make sure arg is evaluated only once. 138 macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg)); 139 macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0))); 140 macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg))); 141 macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg))); 142 macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0)); 143 macro TO_UINT32(arg) = (arg >>> 0); 144 macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg)); 145 macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : NonNumberToNumber(arg)); 146 macro TO_OBJECT_INLINE(arg) = (IS_SPEC_OBJECT(%IS_VAR(arg)) ? arg : ToObject(arg)); 147 macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null"); 148 149 # Macros implemented in Python. 150 python macro CHAR_CODE(str) = ord(str[1]); 151 152 # Constants used on an array to implement the properties of the RegExp object. 153 const REGEXP_NUMBER_OF_CAPTURES = 0; 154 const REGEXP_FIRST_CAPTURE = 3; 155 156 # We can't put macros in macros so we use constants here. 157 # REGEXP_NUMBER_OF_CAPTURES 158 macro NUMBER_OF_CAPTURES(array) = ((array)[0]); 159 160 # Limit according to ECMA 262 15.9.1.1 161 const MAX_TIME_MS = 8640000000000000; 162 # Limit which is MAX_TIME_MS + msPerMonth. 163 const MAX_TIME_BEFORE_UTC = 8640002592000000; 164 165 # Gets the value of a Date object. If arg is not a Date object 166 # a type error is thrown. 167 macro CHECK_DATE(arg) = if (%_ClassOf(arg) !== 'Date') ThrowDateTypeError(); 168 macro LOCAL_DATE_VALUE(arg) = (%_DateField(arg, 0) + %_DateField(arg, 21)); 169 macro UTC_DATE_VALUE(arg) = (%_DateField(arg, 0)); 170 171 macro LOCAL_YEAR(arg) = (%_DateField(arg, 1)); 172 macro LOCAL_MONTH(arg) = (%_DateField(arg, 2)); 173 macro LOCAL_DAY(arg) = (%_DateField(arg, 3)); 174 macro LOCAL_WEEKDAY(arg) = (%_DateField(arg, 4)); 175 macro LOCAL_HOUR(arg) = (%_DateField(arg, 5)); 176 macro LOCAL_MIN(arg) = (%_DateField(arg, 6)); 177 macro LOCAL_SEC(arg) = (%_DateField(arg, 7)); 178 macro LOCAL_MS(arg) = (%_DateField(arg, 8)); 179 macro LOCAL_DAYS(arg) = (%_DateField(arg, 9)); 180 macro LOCAL_TIME_IN_DAY(arg) = (%_DateField(arg, 10)); 181 182 macro UTC_YEAR(arg) = (%_DateField(arg, 11)); 183 macro UTC_MONTH(arg) = (%_DateField(arg, 12)); 184 macro UTC_DAY(arg) = (%_DateField(arg, 13)); 185 macro UTC_WEEKDAY(arg) = (%_DateField(arg, 14)); 186 macro UTC_HOUR(arg) = (%_DateField(arg, 15)); 187 macro UTC_MIN(arg) = (%_DateField(arg, 16)); 188 macro UTC_SEC(arg) = (%_DateField(arg, 17)); 189 macro UTC_MS(arg) = (%_DateField(arg, 18)); 190 macro UTC_DAYS(arg) = (%_DateField(arg, 19)); 191 macro UTC_TIME_IN_DAY(arg) = (%_DateField(arg, 20)); 192 193 macro TIMEZONE_OFFSET(arg) = (%_DateField(arg, 21)); 194 195 macro SET_UTC_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 1)); 196 macro SET_LOCAL_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 0)); 197 198 # Last input and last subject of regexp matches. 199 macro LAST_SUBJECT(array) = ((array)[1]); 200 macro LAST_INPUT(array) = ((array)[2]); 201 202 # REGEXP_FIRST_CAPTURE 203 macro CAPTURE(index) = (3 + (index)); 204 const CAPTURE0 = 3; 205 const CAPTURE1 = 4; 206 207 # PropertyDescriptor return value indices - must match 208 # PropertyDescriptorIndices in runtime.cc. 209 const IS_ACCESSOR_INDEX = 0; 210 const VALUE_INDEX = 1; 211 const GETTER_INDEX = 2; 212 const SETTER_INDEX = 3; 213 const WRITABLE_INDEX = 4; 214 const ENUMERABLE_INDEX = 5; 215 const CONFIGURABLE_INDEX = 6; 216 217 # For messages.js 218 # Matches Script::Type from objects.h 219 const TYPE_NATIVE = 0; 220 const TYPE_EXTENSION = 1; 221 const TYPE_NORMAL = 2; 222 223 # Matches Script::CompilationType from objects.h 224 const COMPILATION_TYPE_HOST = 0; 225 const COMPILATION_TYPE_EVAL = 1; 226 const COMPILATION_TYPE_JSON = 2; 227 228 # Matches Messages::kNoLineNumberInfo from v8.h 229 const kNoLineNumberInfo = 0; 230