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. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +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; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | |
| 48 | const NO_HINT = 0; |
| 49 | const NUMBER_HINT = 1; |
| 50 | const STRING_HINT = 2; |
| 51 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 52 | const kFunctionTag = 0; |
| 53 | const kNewObjectTag = 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 54 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 55 | # For date.js. |
| 56 | const HoursPerDay = 24; |
| 57 | const MinutesPerHour = 60; |
| 58 | const SecondsPerMinute = 60; |
| 59 | const msPerSecond = 1000; |
| 60 | const msPerMinute = 60000; |
| 61 | const msPerHour = 3600000; |
| 62 | const msPerDay = 86400000; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 63 | const msPerMonth = 2592000000; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 64 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 65 | # For apinatives.js |
| 66 | const kUninitialized = -1; |
| 67 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 68 | # Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1). |
| 69 | const kInvalidDate = 'Invalid Date'; |
| 70 | const kDayZeroInJulianDay = 2440588; |
| 71 | const kMonthMask = 0x1e0; |
| 72 | const kDayMask = 0x01f; |
| 73 | const kYearShift = 9; |
| 74 | const kMonthShift = 5; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 75 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 76 | # Type query macros. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 77 | macro IS_NULL(arg) = (arg === null); |
| 78 | macro IS_NULL_OR_UNDEFINED(arg) = (arg == null); |
| 79 | macro IS_UNDEFINED(arg) = (typeof(arg) === 'undefined'); |
| 80 | macro IS_FUNCTION(arg) = (typeof(arg) === 'function'); |
| 81 | macro IS_NUMBER(arg) = (typeof(arg) === 'number'); |
| 82 | macro IS_STRING(arg) = (typeof(arg) === 'string'); |
| 83 | macro IS_OBJECT(arg) = (typeof(arg) === 'object'); |
| 84 | macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean'); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame^] | 85 | macro IS_ARRAY(arg) = (%_IsArray(arg)); |
| 86 | macro IS_REGEXP(arg) = (%_ClassOf(arg) === 'RegExp'); |
| 87 | macro IS_DATE(arg) = (%_ClassOf(arg) === 'Date'); |
| 88 | macro IS_NUMBER_WRAPPER(arg) = (%_ClassOf(arg) === 'Number'); |
| 89 | macro IS_STRING_WRAPPER(arg) = (%_ClassOf(arg) === 'String'); |
| 90 | macro IS_BOOLEAN_WRAPPER(arg) = (%_ClassOf(arg) === 'Boolean'); |
| 91 | macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error'); |
| 92 | macro IS_SCRIPT(arg) = (%_ClassOf(arg) === 'Script'); |
| 93 | macro IS_ARGUMENTS(arg) = (%_ClassOf(arg) === 'Arguments'); |
| 94 | macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global'); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 95 | macro FLOOR(arg) = %Math_floor(arg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 96 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 97 | # Inline macros. Use %IS_VAR to make sure arg is evaluated only once. |
| 98 | macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg)); |
| 99 | macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInteger(arg)); |
| 100 | macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInt32(arg)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 101 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 102 | # Macros implemented in Python. |
| 103 | python macro CHAR_CODE(str) = ord(str[1]); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 104 | |
| 105 | # Accessors for original global properties that ensure they have been loaded. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 106 | const ORIGINAL_REGEXP = (global.RegExp, $RegExp); |
| 107 | const ORIGINAL_DATE = (global.Date, $Date); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 108 | |
| 109 | # Constants used on an array to implement the properties of the RegExp object. |
| 110 | const REGEXP_NUMBER_OF_CAPTURES = 0; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 111 | const REGEXP_FIRST_CAPTURE = 3; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 112 | |
| 113 | # We can't put macros in macros so we use constants here. |
| 114 | # REGEXP_NUMBER_OF_CAPTURES |
| 115 | macro NUMBER_OF_CAPTURES(array) = ((array)[0]); |
| 116 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame^] | 117 | # Gets the value of a Date object. If arg is not a Date object |
| 118 | # a type error is thrown. |
| 119 | macro DATE_VALUE(arg) = (%_ClassOf(arg) === 'Date' ? %_ValueOf(arg) : ThrowDateTypeError()); |
| 120 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 121 | # Last input and last subject are after the captures so we can omit them on |
| 122 | # results returned from global searches. Beware - these evaluate their |
| 123 | # arguments twice. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 124 | macro LAST_SUBJECT(array) = ((array)[1]); |
| 125 | macro LAST_INPUT(array) = ((array)[2]); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 126 | |
| 127 | # REGEXP_FIRST_CAPTURE |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 128 | macro CAPTURE(index) = (3 + (index)); |
| 129 | const CAPTURE0 = 3; |
| 130 | const CAPTURE1 = 4; |