Home | History | Annotate | Download | only in src
      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 
     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 const msPerMonth       = 2592000000;
     64 
     65 # For apinatives.js
     66 const kUninitialized = -1;
     67 
     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;
     75 
     76 # Limits for parts of the date, so that we support all the dates that
     77 # ECMA 262 - 15.9.1.1 requires us to, but at the same time be sure that
     78 # the date (days since 1970) is in SMI range.
     79 const kMinYear  = -1000000;
     80 const kMaxYear  = 1000000;
     81 const kMinMonth = -10000000;
     82 const kMaxMonth = 10000000;
     83 const kMinDate  = -100000000;
     84 const kMaxDate  = 100000000;
     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_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');
    112 macro IS_UNDETECTABLE(arg)      = (%_IsUndetectableObject(arg));
    113 macro FLOOR(arg)                = $floor(arg);
    114 
    115 # Macro for ECMAScript 5 queries of the type:
    116 # "Type(O) is object."
    117 # This is the same as being either a function or an object in V8 terminology.
    118 # In addition, an undetectable object is also included by this.
    119 macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg));
    120 
    121 # Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
    122 macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
    123 macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || arg - arg == 0);
    124 macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg)));
    125 macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
    126 macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));
    127 macro TO_UINT32(arg) = (arg >>> 0);
    128 macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg));
    129 macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : NonNumberToNumber(arg));
    130 
    131 
    132 # Macros implemented in Python.
    133 python macro CHAR_CODE(str) = ord(str[1]);
    134 
    135 # Constants used on an array to implement the properties of the RegExp object.
    136 const REGEXP_NUMBER_OF_CAPTURES = 0;
    137 const REGEXP_FIRST_CAPTURE = 3;
    138 
    139 # We can't put macros in macros so we use constants here.
    140 # REGEXP_NUMBER_OF_CAPTURES
    141 macro NUMBER_OF_CAPTURES(array) = ((array)[0]);
    142 
    143 # Limit according to ECMA 262 15.9.1.1
    144 const MAX_TIME_MS = 8640000000000000;
    145 # Limit which is MAX_TIME_MS + msPerMonth.
    146 const MAX_TIME_BEFORE_UTC = 8640002592000000;
    147 
    148 # Gets the value of a Date object. If arg is not a Date object
    149 # a type error is thrown.
    150 macro DATE_VALUE(arg) = (%_ClassOf(arg) === 'Date' ? %_ValueOf(arg) : ThrowDateTypeError());
    151 macro DAY(time) = ($floor(time / 86400000));
    152 macro NAN_OR_DATE_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : DateFromTime(time));
    153 macro HOUR_FROM_TIME(time) = (Modulo($floor(time / 3600000), 24));
    154 macro MIN_FROM_TIME(time) = (Modulo($floor(time / 60000), 60));
    155 macro NAN_OR_MIN_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : MIN_FROM_TIME(time));
    156 macro SEC_FROM_TIME(time) = (Modulo($floor(time / 1000), 60));
    157 macro NAN_OR_SEC_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : SEC_FROM_TIME(time));
    158 macro MS_FROM_TIME(time) = (Modulo(time, 1000));
    159 macro NAN_OR_MS_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : MS_FROM_TIME(time));
    160 
    161 # Last input and last subject of regexp matches.
    162 macro LAST_SUBJECT(array) = ((array)[1]);
    163 macro LAST_INPUT(array) = ((array)[2]);
    164 
    165 # REGEXP_FIRST_CAPTURE
    166 macro CAPTURE(index) = (3 + (index));
    167 const CAPTURE0 = 3;
    168 const CAPTURE1 = 4;
    169 
    170 # PropertyDescriptor return value indices - must match 
    171 # PropertyDescriptorIndices in runtime.cc.
    172 const IS_ACCESSOR_INDEX = 0;
    173 const VALUE_INDEX = 1;
    174 const GETTER_INDEX = 2;
    175 const SETTER_INDEX = 3;
    176 const WRITABLE_INDEX = 4;
    177 const ENUMERABLE_INDEX = 5;
    178 const CONFIGURABLE_INDEX = 6;
    179