christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1 | # Copyright 2006-2008 Google Inc. 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 | |
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. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | const kApiTagOffset = 0; |
| 42 | const kApiPropertyListOffset = 1; |
| 43 | const kApiSerialNumberOffset = 2; |
| 44 | const kApiConstructorOffset = 2; |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame^] | 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 | |
| 52 | const kFunctionTag = 0; |
| 53 | const kNewObjectTag = 1; |
| 54 | |
| 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; |
| 63 | |
| 64 | # Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1) |
| 65 | const kInvalidDate = 'Invalid Date'; |
| 66 | const kDayZeroInJulianDay = 2440588; |
| 67 | const kMonthMask = 0x1e0; |
| 68 | const kDayMask = 0x01f; |
| 69 | const kYearShift = 9; |
| 70 | const kMonthShift = 5; |
| 71 | |
| 72 | # Type query macros |
| 73 | macro IS_NULL(arg) = (arg === null); |
| 74 | macro IS_NULL_OR_UNDEFINED(arg) = (arg == null); |
| 75 | macro IS_UNDEFINED(arg) = (typeof(arg) === 'undefined'); |
| 76 | macro IS_FUNCTION(arg) = (typeof(arg) === 'function'); |
| 77 | macro IS_NUMBER(arg) = (typeof(arg) === 'number'); |
| 78 | macro IS_STRING(arg) = (typeof(arg) === 'string'); |
| 79 | macro IS_OBJECT(arg) = (typeof(arg) === 'object'); |
| 80 | macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean'); |
| 81 | macro IS_REGEXP(arg) = (%ClassOf(arg) === 'RegExp'); |
| 82 | macro IS_ARRAY(arg) = (%ClassOf(arg) === 'Array'); |
| 83 | macro IS_DATE(arg) = (%ClassOf(arg) === 'Date'); |
| 84 | macro IS_ERROR(arg) = (%ClassOf(arg) === 'Error'); |
| 85 | macro IS_SCRIPT(arg) = (%ClassOf(arg) === 'Script'); |
| 86 | |
| 87 | # 'Inline' macros |
| 88 | # (Make sure arg is evaluated only once via %IS_VAR) |
| 89 | macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInteger(arg)); |
| 90 | macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInt32(arg)); |
| 91 | |
| 92 | python macro CHAR_CODE(str) = ord(str[1]); |
| 93 | |
| 94 | # Accessors for original global properties that ensure they have been loaded. |
| 95 | const ORIGINAL_REGEXP = (global.RegExp, $RegExp); |
| 96 | const ORIGINAL_DATE = (global.Date, $Date); |