blob: b4be15bf4c2849a7b0173163bf1974a2287340c4 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001# 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
Steve Block6ded16b2010-05-10 14:33:55 +010076# 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.
79const kMinYear = -1000000;
80const kMaxYear = 1000000;
81const kMinMonth = -10000000;
82const kMaxMonth = 10000000;
83const kMinDate = -100000000;
84const kMaxDate = 100000000;
85
86# Native cache ids.
87const STRING_TO_REGEXP_CACHE_ID = 0;
88
Steve Blocka7e24c12009-10-30 11:49:00 +000089# Type query macros.
Andrei Popescu402d9372010-02-26 13:31:12 +000090#
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'.
Steve Blocka7e24c12009-10-30 11:49:00 +000094macro IS_NULL(arg) = (arg === null);
95macro IS_NULL_OR_UNDEFINED(arg) = (arg == null);
96macro IS_UNDEFINED(arg) = (typeof(arg) === 'undefined');
Steve Blocka7e24c12009-10-30 11:49:00 +000097macro IS_NUMBER(arg) = (typeof(arg) === 'number');
98macro IS_STRING(arg) = (typeof(arg) === 'string');
Steve Blocka7e24c12009-10-30 11:49:00 +000099macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean');
Steve Blockd0582a62009-12-15 09:54:21 +0000100macro IS_OBJECT(arg) = (%_IsObject(arg));
Steve Blocka7e24c12009-10-30 11:49:00 +0000101macro IS_ARRAY(arg) = (%_IsArray(arg));
Steve Blockd0582a62009-12-15 09:54:21 +0000102macro IS_FUNCTION(arg) = (%_IsFunction(arg));
Andrei Popescu402d9372010-02-26 13:31:12 +0000103macro IS_REGEXP(arg) = (%_IsRegExp(arg));
Steve Blocka7e24c12009-10-30 11:49:00 +0000104macro IS_DATE(arg) = (%_ClassOf(arg) === 'Date');
105macro IS_NUMBER_WRAPPER(arg) = (%_ClassOf(arg) === 'Number');
106macro IS_STRING_WRAPPER(arg) = (%_ClassOf(arg) === 'String');
107macro IS_BOOLEAN_WRAPPER(arg) = (%_ClassOf(arg) === 'Boolean');
108macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error');
109macro IS_SCRIPT(arg) = (%_ClassOf(arg) === 'Script');
110macro IS_ARGUMENTS(arg) = (%_ClassOf(arg) === 'Arguments');
111macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global');
Leon Clarked91b9f72010-01-27 17:25:45 +0000112macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg));
Leon Clarkee46be812010-01-19 14:06:41 +0000113macro FLOOR(arg) = $floor(arg);
Steve Blocka7e24c12009-10-30 11:49:00 +0000114
Kristian Monsen25f61362010-05-21 11:50:48 +0100115# 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.
118macro IS_SPEC_OBJECT_OR_NULL(arg) = (%_IsObject(arg) || %_IsFunction(arg));
119
Steve Blocka7e24c12009-10-30 11:49:00 +0000120# Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
121macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
Andrei Popescu402d9372010-02-26 13:31:12 +0000122macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInteger(arg));
Steve Block8defd9f2010-07-08 12:39:36 +0100123macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
Andrei Popescu402d9372010-02-26 13:31:12 +0000124macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));
125macro TO_UINT32(arg) = (arg >>> 0);
126macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg));
127
Steve Blocka7e24c12009-10-30 11:49:00 +0000128
129# Macros implemented in Python.
130python macro CHAR_CODE(str) = ord(str[1]);
131
Steve Blocka7e24c12009-10-30 11:49:00 +0000132# Constants used on an array to implement the properties of the RegExp object.
133const REGEXP_NUMBER_OF_CAPTURES = 0;
134const REGEXP_FIRST_CAPTURE = 3;
135
136# We can't put macros in macros so we use constants here.
137# REGEXP_NUMBER_OF_CAPTURES
138macro NUMBER_OF_CAPTURES(array) = ((array)[0]);
139
Steve Block6ded16b2010-05-10 14:33:55 +0100140# Limit according to ECMA 262 15.9.1.1
141const MAX_TIME_MS = 8640000000000000;
142
Steve Blocka7e24c12009-10-30 11:49:00 +0000143# Gets the value of a Date object. If arg is not a Date object
144# a type error is thrown.
145macro DATE_VALUE(arg) = (%_ClassOf(arg) === 'Date' ? %_ValueOf(arg) : ThrowDateTypeError());
Leon Clarkee46be812010-01-19 14:06:41 +0000146macro DAY(time) = ($floor(time / 86400000));
Steve Block6ded16b2010-05-10 14:33:55 +0100147macro MONTH_FROM_TIME(time) = (MonthFromTime(time));
148macro DATE_FROM_TIME(time) = (DateFromTime(time));
Leon Clarkeac952652010-07-15 11:15:24 +0100149macro NAN_OR_DATE_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : DATE_FROM_TIME(time));
Steve Block6ded16b2010-05-10 14:33:55 +0100150macro YEAR_FROM_TIME(time) = (YearFromTime(time));
Leon Clarkee46be812010-01-19 14:06:41 +0000151macro HOUR_FROM_TIME(time) = (Modulo($floor(time / 3600000), 24));
152macro MIN_FROM_TIME(time) = (Modulo($floor(time / 60000), 60));
Leon Clarkeac952652010-07-15 11:15:24 +0100153macro NAN_OR_MIN_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : MIN_FROM_TIME(time));
Leon Clarkee46be812010-01-19 14:06:41 +0000154macro SEC_FROM_TIME(time) = (Modulo($floor(time / 1000), 60));
Leon Clarkeac952652010-07-15 11:15:24 +0100155macro NAN_OR_SEC_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : SEC_FROM_TIME(time));
Leon Clarkee46be812010-01-19 14:06:41 +0000156macro MS_FROM_TIME(time) = (Modulo(time, 1000));
Leon Clarkeac952652010-07-15 11:15:24 +0100157macro NAN_OR_MS_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : MS_FROM_TIME(time));
Steve Blocka7e24c12009-10-30 11:49:00 +0000158
Steve Block3ce2e202009-11-05 08:53:23 +0000159# Last input and last subject of regexp matches.
Steve Blocka7e24c12009-10-30 11:49:00 +0000160macro LAST_SUBJECT(array) = ((array)[1]);
161macro LAST_INPUT(array) = ((array)[2]);
162
163# REGEXP_FIRST_CAPTURE
164macro CAPTURE(index) = (3 + (index));
165const CAPTURE0 = 3;
166const CAPTURE1 = 4;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100167
168# PropertyDescriptor return value indices - must match
169# PropertyDescriptorIndices in runtime.cc.
170const IS_ACCESSOR_INDEX = 0;
171const VALUE_INDEX = 1;
172const GETTER_INDEX = 2;
173const SETTER_INDEX = 3;
174const WRITABLE_INDEX = 4;
175const ENUMERABLE_INDEX = 5;
176const CONFIGURABLE_INDEX = 6;