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 31const NONE = 0; 32const READ_ONLY = 1; 33const DONT_ENUM = 2; 34const DONT_DELETE = 4; 35 36# Constants used for getter and setter operations. 37const GETTER = 0; 38const SETTER = 1; 39 40# These definitions must match the index of the properties in objects.h. 41const kApiTagOffset = 0; 42const kApiPropertyListOffset = 1; 43const kApiSerialNumberOffset = 2; 44const kApiConstructorOffset = 2; 45const kApiPrototypeTemplateOffset = 5; 46const kApiParentTemplateOffset = 6; 47 48const NO_HINT = 0; 49const NUMBER_HINT = 1; 50const STRING_HINT = 2; 51 52const kFunctionTag = 0; 53const kNewObjectTag = 1; 54 55# For date.js. 56const HoursPerDay = 24; 57const MinutesPerHour = 60; 58const SecondsPerMinute = 60; 59const msPerSecond = 1000; 60const msPerMinute = 60000; 61const msPerHour = 3600000; 62const msPerDay = 86400000; 63const msPerMonth = 2592000000; 64 65# For apinatives.js 66const kUninitialized = -1; 67 68# Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1). 69const kInvalidDate = 'Invalid Date'; 70const kDayZeroInJulianDay = 2440588; 71const kMonthMask = 0x1e0; 72const kDayMask = 0x01f; 73const kYearShift = 9; 74const kMonthShift = 5; 75 76# Type query macros. 77# 78# Note: We have special support for typeof(foo) === 'bar' in the compiler. 79# It will *not* generate a runtime typeof call for the most important 80# values of 'bar'. 81macro IS_NULL(arg) = (arg === null); 82macro IS_NULL_OR_UNDEFINED(arg) = (arg == null); 83macro IS_UNDEFINED(arg) = (typeof(arg) === 'undefined'); 84macro IS_NUMBER(arg) = (typeof(arg) === 'number'); 85macro IS_STRING(arg) = (typeof(arg) === 'string'); 86macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean'); 87macro IS_OBJECT(arg) = (%_IsObject(arg)); 88macro IS_ARRAY(arg) = (%_IsArray(arg)); 89macro IS_FUNCTION(arg) = (%_IsFunction(arg)); 90macro IS_REGEXP(arg) = (%_IsRegExp(arg)); 91macro IS_DATE(arg) = (%_ClassOf(arg) === 'Date'); 92macro IS_NUMBER_WRAPPER(arg) = (%_ClassOf(arg) === 'Number'); 93macro IS_STRING_WRAPPER(arg) = (%_ClassOf(arg) === 'String'); 94macro IS_BOOLEAN_WRAPPER(arg) = (%_ClassOf(arg) === 'Boolean'); 95macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error'); 96macro IS_SCRIPT(arg) = (%_ClassOf(arg) === 'Script'); 97macro IS_ARGUMENTS(arg) = (%_ClassOf(arg) === 'Arguments'); 98macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global'); 99macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg)); 100macro FLOOR(arg) = $floor(arg); 101 102# Inline macros. Use %IS_VAR to make sure arg is evaluated only once. 103macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg)); 104macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInteger(arg)); 105macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0)); 106macro TO_UINT32(arg) = (arg >>> 0); 107macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg)); 108 109 110# Macros implemented in Python. 111python macro CHAR_CODE(str) = ord(str[1]); 112 113# Constants used on an array to implement the properties of the RegExp object. 114const REGEXP_NUMBER_OF_CAPTURES = 0; 115const REGEXP_FIRST_CAPTURE = 3; 116 117# We can't put macros in macros so we use constants here. 118# REGEXP_NUMBER_OF_CAPTURES 119macro NUMBER_OF_CAPTURES(array) = ((array)[0]); 120 121# Gets the value of a Date object. If arg is not a Date object 122# a type error is thrown. 123macro DATE_VALUE(arg) = (%_ClassOf(arg) === 'Date' ? %_ValueOf(arg) : ThrowDateTypeError()); 124macro DAY(time) = ($floor(time / 86400000)); 125macro MONTH_FROM_TIME(time) = (FromJulianDay(($floor(time / 86400000)) + 2440588).month); 126macro DATE_FROM_TIME(time) = (FromJulianDay(($floor(time / 86400000)) + 2440588).date); 127macro YEAR_FROM_TIME(time) = (FromJulianDay(($floor(time / 86400000)) + 2440588).year); 128macro HOUR_FROM_TIME(time) = (Modulo($floor(time / 3600000), 24)); 129macro MIN_FROM_TIME(time) = (Modulo($floor(time / 60000), 60)); 130macro SEC_FROM_TIME(time) = (Modulo($floor(time / 1000), 60)); 131macro MS_FROM_TIME(time) = (Modulo(time, 1000)); 132 133# Last input and last subject of regexp matches. 134macro LAST_SUBJECT(array) = ((array)[1]); 135macro LAST_INPUT(array) = ((array)[2]); 136 137# REGEXP_FIRST_CAPTURE 138macro CAPTURE(index) = (3 + (index)); 139const CAPTURE0 = 3; 140const CAPTURE1 = 4; 141