Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 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. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 41 | const kApiTagOffset = 0; |
| 42 | const kApiPropertyListOffset = 1; |
| 43 | const kApiSerialNumberOffset = 2; |
| 44 | const kApiConstructorOffset = 2; |
| 45 | const kApiPrototypeTemplateOffset = 5; |
| 46 | const kApiParentTemplateOffset = 6; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 47 | const kApiFlagOffset = 14; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 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; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 68 | const kReadOnlyPrototypeBit = 3; # For FunctionTemplateInfo, matches objects.h |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 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 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 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; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 85 | |
| 86 | # Native cache ids. |
| 87 | const STRING_TO_REGEXP_CACHE_ID = 0; |
| 88 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 89 | # Type query macros. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 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'. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 94 | macro IS_NULL(arg) = (arg === null); |
| 95 | macro IS_NULL_OR_UNDEFINED(arg) = (arg == null); |
| 96 | macro IS_UNDEFINED(arg) = (typeof(arg) === 'undefined'); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 97 | macro IS_NUMBER(arg) = (typeof(arg) === 'number'); |
| 98 | macro IS_STRING(arg) = (typeof(arg) === 'string'); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 99 | macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean'); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 100 | macro IS_OBJECT(arg) = (%_IsObject(arg)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 101 | macro IS_ARRAY(arg) = (%_IsArray(arg)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 102 | macro IS_FUNCTION(arg) = (%_IsFunction(arg)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 103 | macro IS_REGEXP(arg) = (%_IsRegExp(arg)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 104 | macro IS_DATE(arg) = (%_ClassOf(arg) === 'Date'); |
| 105 | macro IS_NUMBER_WRAPPER(arg) = (%_ClassOf(arg) === 'Number'); |
| 106 | macro IS_STRING_WRAPPER(arg) = (%_ClassOf(arg) === 'String'); |
| 107 | macro IS_BOOLEAN_WRAPPER(arg) = (%_ClassOf(arg) === 'Boolean'); |
| 108 | macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error'); |
| 109 | macro IS_SCRIPT(arg) = (%_ClassOf(arg) === 'Script'); |
| 110 | macro IS_ARGUMENTS(arg) = (%_ClassOf(arg) === 'Arguments'); |
| 111 | macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global'); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 112 | macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 113 | macro FLOOR(arg) = $floor(arg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 114 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 115 | # Macro for ECMAScript 5 queries of the type: |
| 116 | # "Type(O) is object." |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 117 | # This is the same as being either a function or an object in V8 terminology |
| 118 | # (including proxies). |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 119 | # In addition, an undetectable object is also included by this. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 120 | macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg)); |
| 121 | |
| 122 | # Macro for ECMAScript 5 queries of the type: |
| 123 | # "IsCallable(O)" |
| 124 | # We assume here that this is the same as being either a function or a function |
| 125 | # proxy. That ignores host objects with [[Call]] methods, but in most situations |
| 126 | # we cannot handle those anyway. |
| 127 | macro IS_SPEC_FUNCTION(arg) = (%_ClassOf(arg) === 'Function'); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 128 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 129 | # Indices in bound function info retrieved by %BoundFunctionGetBindings(...). |
| 130 | const kBoundFunctionIndex = 0; |
| 131 | const kBoundThisIndex = 1; |
| 132 | const kBoundArgumentsStartIndex = 2; |
| 133 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 134 | # Inline macros. Use %IS_VAR to make sure arg is evaluated only once. |
| 135 | macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 136 | macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 137 | macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg))); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 138 | macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg))); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 139 | macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0)); |
| 140 | macro TO_UINT32(arg) = (arg >>> 0); |
| 141 | macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg)); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 142 | macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : NonNumberToNumber(arg)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 143 | macro TO_OBJECT_INLINE(arg) = (IS_SPEC_OBJECT(%IS_VAR(arg)) ? arg : ToObject(arg)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 144 | macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 145 | |
| 146 | # Macros implemented in Python. |
| 147 | python macro CHAR_CODE(str) = ord(str[1]); |
| 148 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 149 | # Constants used on an array to implement the properties of the RegExp object. |
| 150 | const REGEXP_NUMBER_OF_CAPTURES = 0; |
| 151 | const REGEXP_FIRST_CAPTURE = 3; |
| 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 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 157 | # Limit according to ECMA 262 15.9.1.1 |
| 158 | const MAX_TIME_MS = 8640000000000000; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 159 | # Limit which is MAX_TIME_MS + msPerMonth. |
| 160 | const MAX_TIME_BEFORE_UTC = 8640002592000000; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 161 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 162 | # Gets the value of a Date object. If arg is not a Date object |
| 163 | # a type error is thrown. |
| 164 | macro DATE_VALUE(arg) = (%_ClassOf(arg) === 'Date' ? %_ValueOf(arg) : ThrowDateTypeError()); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 165 | macro DAY(time) = ($floor(time / 86400000)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 166 | macro NAN_OR_DATE_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : DateFromTime(time)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 167 | macro HOUR_FROM_TIME(time) = (Modulo($floor(time / 3600000), 24)); |
| 168 | macro MIN_FROM_TIME(time) = (Modulo($floor(time / 60000), 60)); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 169 | macro NAN_OR_MIN_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : MIN_FROM_TIME(time)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 170 | macro SEC_FROM_TIME(time) = (Modulo($floor(time / 1000), 60)); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 171 | macro NAN_OR_SEC_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : SEC_FROM_TIME(time)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 172 | macro MS_FROM_TIME(time) = (Modulo(time, 1000)); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 173 | macro NAN_OR_MS_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : MS_FROM_TIME(time)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 174 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 175 | # Last input and last subject of regexp matches. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 176 | macro LAST_SUBJECT(array) = ((array)[1]); |
| 177 | macro LAST_INPUT(array) = ((array)[2]); |
| 178 | |
| 179 | # REGEXP_FIRST_CAPTURE |
| 180 | macro CAPTURE(index) = (3 + (index)); |
| 181 | const CAPTURE0 = 3; |
| 182 | const CAPTURE1 = 4; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 183 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 184 | # PropertyDescriptor return value indices - must match |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 185 | # PropertyDescriptorIndices in runtime.cc. |
| 186 | const IS_ACCESSOR_INDEX = 0; |
| 187 | const VALUE_INDEX = 1; |
| 188 | const GETTER_INDEX = 2; |
| 189 | const SETTER_INDEX = 3; |
| 190 | const WRITABLE_INDEX = 4; |
| 191 | const ENUMERABLE_INDEX = 5; |
| 192 | const CONFIGURABLE_INDEX = 6; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 193 | |
| 194 | # For messages.js |
| 195 | # Matches Script::Type from objects.h |
| 196 | const TYPE_NATIVE = 0; |
| 197 | const TYPE_EXTENSION = 1; |
| 198 | const TYPE_NORMAL = 2; |
| 199 | |
| 200 | # Matches Script::CompilationType from objects.h |
| 201 | const COMPILATION_TYPE_HOST = 0; |
| 202 | const COMPILATION_TYPE_EVAL = 1; |
| 203 | const COMPILATION_TYPE_JSON = 2; |
| 204 | |
| 205 | # Matches Messages::kNoLineNumberInfo from v8.h |
| 206 | const kNoLineNumberInfo = 0; |