kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1 | # Copyright 2006-2009 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 31 | const NONE = 0; |
| 32 | const READ_ONLY = 1; |
| 33 | const DONT_ENUM = 2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | const DONT_DELETE = 4; |
| 35 | |
| 36 | # Constants used for getter and setter operations. |
| 37 | const GETTER = 0; |
| 38 | const SETTER = 1; |
| 39 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 40 | # These definitions must match the index of the properties in objects.h. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +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; |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 47 | const kApiFlagOffset = 14; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | |
| 49 | const NO_HINT = 0; |
| 50 | const NUMBER_HINT = 1; |
| 51 | const STRING_HINT = 2; |
| 52 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 53 | const kFunctionTag = 0; |
| 54 | const kNewObjectTag = 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 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; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 64 | const msPerMonth = 2592000000; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 66 | # For apinatives.js |
| 67 | const kUninitialized = -1; |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 68 | const kReadOnlyPrototypeBit = 3; # For FunctionTemplateInfo, matches objects.h |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 69 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 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; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 77 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [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; |
| 85 | const kMinDate = -100000000; |
| 86 | const kMaxDate = 100000000; |
| 87 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 88 | # Native cache ids. |
| 89 | const STRING_TO_REGEXP_CACHE_ID = 0; |
| 90 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 91 | # Type query macros. |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 92 | # |
| 93 | # Note: We have special support for typeof(foo) === 'bar' in the compiler. |
| 94 | # It will *not* generate a runtime typeof call for the most important |
| 95 | # values of 'bar'. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 96 | macro IS_NULL(arg) = (arg === null); |
| 97 | macro IS_NULL_OR_UNDEFINED(arg) = (arg == null); |
| 98 | macro IS_UNDEFINED(arg) = (typeof(arg) === 'undefined'); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 99 | macro IS_NUMBER(arg) = (typeof(arg) === 'number'); |
| 100 | macro IS_STRING(arg) = (typeof(arg) === 'string'); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 101 | macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean'); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 102 | macro IS_OBJECT(arg) = (%_IsObject(arg)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 103 | macro IS_ARRAY(arg) = (%_IsArray(arg)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 104 | macro IS_FUNCTION(arg) = (%_IsFunction(arg)); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 105 | macro IS_REGEXP(arg) = (%_IsRegExp(arg)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 106 | macro IS_DATE(arg) = (%_ClassOf(arg) === 'Date'); |
| 107 | macro IS_NUMBER_WRAPPER(arg) = (%_ClassOf(arg) === 'Number'); |
| 108 | macro IS_STRING_WRAPPER(arg) = (%_ClassOf(arg) === 'String'); |
| 109 | macro IS_BOOLEAN_WRAPPER(arg) = (%_ClassOf(arg) === 'Boolean'); |
| 110 | macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error'); |
| 111 | macro IS_SCRIPT(arg) = (%_ClassOf(arg) === 'Script'); |
| 112 | macro IS_ARGUMENTS(arg) = (%_ClassOf(arg) === 'Arguments'); |
| 113 | macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global'); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 114 | macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 115 | macro FLOOR(arg) = $floor(arg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 116 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 117 | # Macro for ECMAScript 5 queries of the type: |
| 118 | # "Type(O) is object." |
| 119 | # This is the same as being either a function or an object in V8 terminology. |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 120 | # In addition, an undetectable object is also included by this. |
| 121 | macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg)); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 122 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 123 | # Inline macros. Use %IS_VAR to make sure arg is evaluated only once. |
| 124 | macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 125 | macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || arg - arg == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 126 | macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg))); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 127 | macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg))); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 128 | macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0)); |
| 129 | macro TO_UINT32(arg) = (arg >>> 0); |
| 130 | macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 131 | macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : NonNumberToNumber(arg)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 132 | macro TO_OBJECT_INLINE(arg) = (IS_SPEC_OBJECT(%IS_VAR(arg)) ? arg : ToObject(arg)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 133 | macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 134 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 135 | # Macros implemented in Python. |
| 136 | python macro CHAR_CODE(str) = ord(str[1]); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 137 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 138 | # Constants used on an array to implement the properties of the RegExp object. |
| 139 | const REGEXP_NUMBER_OF_CAPTURES = 0; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 140 | const REGEXP_FIRST_CAPTURE = 3; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 141 | |
| 142 | # We can't put macros in macros so we use constants here. |
| 143 | # REGEXP_NUMBER_OF_CAPTURES |
| 144 | macro NUMBER_OF_CAPTURES(array) = ((array)[0]); |
| 145 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 146 | # Limit according to ECMA 262 15.9.1.1 |
| 147 | const MAX_TIME_MS = 8640000000000000; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 148 | # Limit which is MAX_TIME_MS + msPerMonth. |
| 149 | const MAX_TIME_BEFORE_UTC = 8640002592000000; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 150 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 151 | # Gets the value of a Date object. If arg is not a Date object |
| 152 | # a type error is thrown. |
| 153 | macro DATE_VALUE(arg) = (%_ClassOf(arg) === 'Date' ? %_ValueOf(arg) : ThrowDateTypeError()); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 154 | macro DAY(time) = ($floor(time / 86400000)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 155 | macro NAN_OR_DATE_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : DateFromTime(time)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 156 | macro HOUR_FROM_TIME(time) = (Modulo($floor(time / 3600000), 24)); |
| 157 | macro MIN_FROM_TIME(time) = (Modulo($floor(time / 60000), 60)); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 158 | macro NAN_OR_MIN_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : MIN_FROM_TIME(time)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 159 | macro SEC_FROM_TIME(time) = (Modulo($floor(time / 1000), 60)); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 160 | macro NAN_OR_SEC_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : SEC_FROM_TIME(time)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 161 | macro MS_FROM_TIME(time) = (Modulo(time, 1000)); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 162 | macro NAN_OR_MS_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : MS_FROM_TIME(time)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 163 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 164 | # Last input and last subject of regexp matches. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 165 | macro LAST_SUBJECT(array) = ((array)[1]); |
| 166 | macro LAST_INPUT(array) = ((array)[2]); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 167 | |
| 168 | # REGEXP_FIRST_CAPTURE |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 169 | macro CAPTURE(index) = (3 + (index)); |
| 170 | const CAPTURE0 = 3; |
| 171 | const CAPTURE1 = 4; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 172 | |
| 173 | # PropertyDescriptor return value indices - must match |
| 174 | # PropertyDescriptorIndices in runtime.cc. |
| 175 | const IS_ACCESSOR_INDEX = 0; |
| 176 | const VALUE_INDEX = 1; |
| 177 | const GETTER_INDEX = 2; |
| 178 | const SETTER_INDEX = 3; |
| 179 | const WRITABLE_INDEX = 4; |
| 180 | const ENUMERABLE_INDEX = 5; |
| 181 | const CONFIGURABLE_INDEX = 6; |