blob: 93287ae3d44a378bbfff81fc4f211fe6b8d0f890 [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.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010029# Used for defines that must be defined for all native JS files.
Steve Blocka7e24c12009-10-30 11:49:00 +000030
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.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000041const kApiTagOffset = 0;
42const kApiPropertyListOffset = 1;
43const kApiSerialNumberOffset = 2;
44const kApiConstructorOffset = 2;
45const kApiPrototypeTemplateOffset = 5;
46const kApiParentTemplateOffset = 6;
Ben Murdoch69a99ed2011-11-30 16:03:39 +000047const kApiFlagOffset = 14;
Steve Blocka7e24c12009-10-30 11:49:00 +000048
49const NO_HINT = 0;
50const NUMBER_HINT = 1;
51const STRING_HINT = 2;
52
53const kFunctionTag = 0;
54const kNewObjectTag = 1;
55
56# For date.js.
57const HoursPerDay = 24;
58const MinutesPerHour = 60;
59const SecondsPerMinute = 60;
60const msPerSecond = 1000;
61const msPerMinute = 60000;
62const msPerHour = 3600000;
63const msPerDay = 86400000;
64const msPerMonth = 2592000000;
65
66# For apinatives.js
67const kUninitialized = -1;
Ben Murdoch69a99ed2011-11-30 16:03:39 +000068const kReadOnlyPrototypeBit = 3; # For FunctionTemplateInfo, matches objects.h
Steve Blocka7e24c12009-10-30 11:49:00 +000069
70# Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1).
71const kInvalidDate = 'Invalid Date';
72const kDayZeroInJulianDay = 2440588;
73const kMonthMask = 0x1e0;
74const kDayMask = 0x01f;
75const kYearShift = 9;
76const kMonthShift = 5;
77
Steve Block6ded16b2010-05-10 14:33:55 +010078# Limits for parts of the date, so that we support all the dates that
79# ECMA 262 - 15.9.1.1 requires us to, but at the same time be sure that
80# the date (days since 1970) is in SMI range.
81const kMinYear = -1000000;
82const kMaxYear = 1000000;
83const kMinMonth = -10000000;
84const kMaxMonth = 10000000;
Steve Block6ded16b2010-05-10 14:33:55 +010085
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));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100104macro IS_SET(arg) = (%_ClassOf(arg) === 'Set');
105macro IS_MAP(arg) = (%_ClassOf(arg) === 'Map');
106macro IS_WEAKMAP(arg) = (%_ClassOf(arg) === 'WeakMap');
Steve Blocka7e24c12009-10-30 11:49:00 +0000107macro IS_DATE(arg) = (%_ClassOf(arg) === 'Date');
108macro IS_NUMBER_WRAPPER(arg) = (%_ClassOf(arg) === 'Number');
109macro IS_STRING_WRAPPER(arg) = (%_ClassOf(arg) === 'String');
110macro IS_BOOLEAN_WRAPPER(arg) = (%_ClassOf(arg) === 'Boolean');
111macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error');
112macro IS_SCRIPT(arg) = (%_ClassOf(arg) === 'Script');
113macro IS_ARGUMENTS(arg) = (%_ClassOf(arg) === 'Arguments');
114macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global');
Leon Clarked91b9f72010-01-27 17:25:45 +0000115macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg));
Leon Clarkee46be812010-01-19 14:06:41 +0000116macro FLOOR(arg) = $floor(arg);
Steve Blocka7e24c12009-10-30 11:49:00 +0000117
Kristian Monsen25f61362010-05-21 11:50:48 +0100118# Macro for ECMAScript 5 queries of the type:
119# "Type(O) is object."
Ben Murdoch589d6972011-11-30 16:04:58 +0000120# This is the same as being either a function or an object in V8 terminology
121# (including proxies).
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100122# In addition, an undetectable object is also included by this.
Ben Murdoch589d6972011-11-30 16:04:58 +0000123macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg));
124
125# Macro for ECMAScript 5 queries of the type:
126# "IsCallable(O)"
127# We assume here that this is the same as being either a function or a function
128# proxy. That ignores host objects with [[Call]] methods, but in most situations
129# we cannot handle those anyway.
130macro IS_SPEC_FUNCTION(arg) = (%_ClassOf(arg) === 'Function');
Kristian Monsen25f61362010-05-21 11:50:48 +0100131
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100132# Indices in bound function info retrieved by %BoundFunctionGetBindings(...).
133const kBoundFunctionIndex = 0;
134const kBoundThisIndex = 1;
135const kBoundArgumentsStartIndex = 2;
136
Steve Blocka7e24c12009-10-30 11:49:00 +0000137# Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
138macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
Ben Murdoch589d6972011-11-30 16:04:58 +0000139macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0)));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100140macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg)));
Steve Block8defd9f2010-07-08 12:39:36 +0100141macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
Andrei Popescu402d9372010-02-26 13:31:12 +0000142macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));
143macro TO_UINT32(arg) = (arg >>> 0);
144macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg));
Ben Murdoch086aeea2011-05-13 15:57:08 +0100145macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : NonNumberToNumber(arg));
Ben Murdoch257744e2011-11-30 15:57:28 +0000146macro TO_OBJECT_INLINE(arg) = (IS_SPEC_OBJECT(%IS_VAR(arg)) ? arg : ToObject(arg));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000147macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null");
Steve Blocka7e24c12009-10-30 11:49:00 +0000148
149# Macros implemented in Python.
150python macro CHAR_CODE(str) = ord(str[1]);
151
Steve Blocka7e24c12009-10-30 11:49:00 +0000152# Constants used on an array to implement the properties of the RegExp object.
153const REGEXP_NUMBER_OF_CAPTURES = 0;
154const REGEXP_FIRST_CAPTURE = 3;
155
156# We can't put macros in macros so we use constants here.
157# REGEXP_NUMBER_OF_CAPTURES
158macro NUMBER_OF_CAPTURES(array) = ((array)[0]);
159
Steve Block6ded16b2010-05-10 14:33:55 +0100160# Limit according to ECMA 262 15.9.1.1
161const MAX_TIME_MS = 8640000000000000;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100162# Limit which is MAX_TIME_MS + msPerMonth.
163const MAX_TIME_BEFORE_UTC = 8640002592000000;
Steve Block6ded16b2010-05-10 14:33:55 +0100164
Steve Blocka7e24c12009-10-30 11:49:00 +0000165# Gets the value of a Date object. If arg is not a Date object
166# a type error is thrown.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100167macro CHECK_DATE(arg) = if (%_ClassOf(arg) !== 'Date') ThrowDateTypeError();
168macro LOCAL_DATE_VALUE(arg) = (%_DateField(arg, 0) + %_DateField(arg, 21));
169macro UTC_DATE_VALUE(arg) = (%_DateField(arg, 0));
170
171macro LOCAL_YEAR(arg) = (%_DateField(arg, 1));
172macro LOCAL_MONTH(arg) = (%_DateField(arg, 2));
173macro LOCAL_DAY(arg) = (%_DateField(arg, 3));
174macro LOCAL_WEEKDAY(arg) = (%_DateField(arg, 4));
175macro LOCAL_HOUR(arg) = (%_DateField(arg, 5));
176macro LOCAL_MIN(arg) = (%_DateField(arg, 6));
177macro LOCAL_SEC(arg) = (%_DateField(arg, 7));
178macro LOCAL_MS(arg) = (%_DateField(arg, 8));
179macro LOCAL_DAYS(arg) = (%_DateField(arg, 9));
180macro LOCAL_TIME_IN_DAY(arg) = (%_DateField(arg, 10));
181
182macro UTC_YEAR(arg) = (%_DateField(arg, 11));
183macro UTC_MONTH(arg) = (%_DateField(arg, 12));
184macro UTC_DAY(arg) = (%_DateField(arg, 13));
185macro UTC_WEEKDAY(arg) = (%_DateField(arg, 14));
186macro UTC_HOUR(arg) = (%_DateField(arg, 15));
187macro UTC_MIN(arg) = (%_DateField(arg, 16));
188macro UTC_SEC(arg) = (%_DateField(arg, 17));
189macro UTC_MS(arg) = (%_DateField(arg, 18));
190macro UTC_DAYS(arg) = (%_DateField(arg, 19));
191macro UTC_TIME_IN_DAY(arg) = (%_DateField(arg, 20));
192
193macro TIMEZONE_OFFSET(arg) = (%_DateField(arg, 21));
194
195macro SET_UTC_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 1));
196macro SET_LOCAL_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 0));
Steve Blocka7e24c12009-10-30 11:49:00 +0000197
Steve Block3ce2e202009-11-05 08:53:23 +0000198# Last input and last subject of regexp matches.
Steve Blocka7e24c12009-10-30 11:49:00 +0000199macro LAST_SUBJECT(array) = ((array)[1]);
200macro LAST_INPUT(array) = ((array)[2]);
201
202# REGEXP_FIRST_CAPTURE
203macro CAPTURE(index) = (3 + (index));
204const CAPTURE0 = 3;
205const CAPTURE1 = 4;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100206
Ben Murdoch589d6972011-11-30 16:04:58 +0000207# PropertyDescriptor return value indices - must match
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100208# PropertyDescriptorIndices in runtime.cc.
209const IS_ACCESSOR_INDEX = 0;
210const VALUE_INDEX = 1;
211const GETTER_INDEX = 2;
212const SETTER_INDEX = 3;
213const WRITABLE_INDEX = 4;
214const ENUMERABLE_INDEX = 5;
215const CONFIGURABLE_INDEX = 6;
Ben Murdoch589d6972011-11-30 16:04:58 +0000216
217# For messages.js
218# Matches Script::Type from objects.h
219const TYPE_NATIVE = 0;
220const TYPE_EXTENSION = 1;
221const TYPE_NORMAL = 2;
222
223# Matches Script::CompilationType from objects.h
224const COMPILATION_TYPE_HOST = 0;
225const COMPILATION_TYPE_EVAL = 1;
226const COMPILATION_TYPE_JSON = 2;
227
228# Matches Messages::kNoLineNumberInfo from v8.h
229const kNoLineNumberInfo = 0;