blob: 291a898f53d22b26a15b4bdf61deea00dd4e8149 [file] [log] [blame]
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001# Copyright 2006-2009 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002# 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.
ulan@chromium.org2efb9002012-01-19 15:36:35 +000029# Used for defines that must be defined for all native JS files.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000030
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000031const NONE = 0;
32const READ_ONLY = 1;
33const DONT_ENUM = 2;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000034const DONT_DELETE = 4;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +000035const NEW_ONE_BYTE_STRING = true;
36const NEW_TWO_BYTE_STRING = false;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000037
38# Constants used for getter and setter operations.
39const GETTER = 0;
40const SETTER = 1;
41
kasper.lund212ac232008-07-16 07:07:30 +000042# These definitions must match the index of the properties in objects.h.
ager@chromium.org04921a82011-06-27 13:21:41 +000043const kApiTagOffset = 0;
44const kApiPropertyListOffset = 1;
45const kApiSerialNumberOffset = 2;
46const kApiConstructorOffset = 2;
47const kApiPrototypeTemplateOffset = 5;
48const kApiParentTemplateOffset = 6;
ricow@chromium.org2c99e282011-07-28 09:15:17 +000049const kApiFlagOffset = 14;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000050
51const NO_HINT = 0;
52const NUMBER_HINT = 1;
53const STRING_HINT = 2;
54
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000055const kFunctionTag = 0;
56const kNewObjectTag = 1;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000057
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000058# For date.js.
59const HoursPerDay = 24;
60const MinutesPerHour = 60;
61const SecondsPerMinute = 60;
62const msPerSecond = 1000;
63const msPerMinute = 60000;
64const msPerHour = 3600000;
65const msPerDay = 86400000;
ager@chromium.orgeadaf222009-06-16 09:43:10 +000066const msPerMonth = 2592000000;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000067
ager@chromium.org32912102009-01-16 10:38:43 +000068# For apinatives.js
69const kUninitialized = -1;
ricow@chromium.org2c99e282011-07-28 09:15:17 +000070const kReadOnlyPrototypeBit = 3; # For FunctionTemplateInfo, matches objects.h
ager@chromium.org32912102009-01-16 10:38:43 +000071
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000072# Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1).
73const kInvalidDate = 'Invalid Date';
74const kDayZeroInJulianDay = 2440588;
75const kMonthMask = 0x1e0;
76const kDayMask = 0x01f;
77const kYearShift = 9;
78const kMonthShift = 5;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000079
ager@chromium.orgce5e87b2010-03-10 10:24:18 +000080# Limits for parts of the date, so that we support all the dates that
81# ECMA 262 - 15.9.1.1 requires us to, but at the same time be sure that
82# the date (days since 1970) is in SMI range.
83const kMinYear = -1000000;
84const kMaxYear = 1000000;
85const kMinMonth = -10000000;
86const kMaxMonth = 10000000;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +000087
ricow@chromium.orgc9c80822010-04-21 08:22:37 +000088# Native cache ids.
89const STRING_TO_REGEXP_CACHE_ID = 0;
90
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000091# Type query macros.
fschneider@chromium.orgb95b98b2010-02-23 10:34:29 +000092#
93# Note: We have special support for typeof(foo) === 'bar' in the compiler.
94# It will *not* generate a runtime typeof call for the most important
95# values of 'bar'.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000096macro IS_NULL(arg) = (arg === null);
97macro IS_NULL_OR_UNDEFINED(arg) = (arg == null);
98macro IS_UNDEFINED(arg) = (typeof(arg) === 'undefined');
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000099macro IS_NUMBER(arg) = (typeof(arg) === 'number');
100macro IS_STRING(arg) = (typeof(arg) === 'string');
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000101macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean');
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000102macro IS_SYMBOL(arg) = (%_IsSymbol(arg));
ager@chromium.org6141cbe2009-11-20 12:14:52 +0000103macro IS_OBJECT(arg) = (%_IsObject(arg));
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000104macro IS_ARRAY(arg) = (%_IsArray(arg));
ager@chromium.org6141cbe2009-11-20 12:14:52 +0000105macro IS_FUNCTION(arg) = (%_IsFunction(arg));
fschneider@chromium.orgb95b98b2010-02-23 10:34:29 +0000106macro IS_REGEXP(arg) = (%_IsRegExp(arg));
rossberg@chromium.orgfab14982012-01-05 15:02:15 +0000107macro IS_SET(arg) = (%_ClassOf(arg) === 'Set');
108macro IS_MAP(arg) = (%_ClassOf(arg) === 'Map');
109macro IS_WEAKMAP(arg) = (%_ClassOf(arg) === 'WeakMap');
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000110macro IS_DATE(arg) = (%_ClassOf(arg) === 'Date');
111macro IS_NUMBER_WRAPPER(arg) = (%_ClassOf(arg) === 'Number');
112macro IS_STRING_WRAPPER(arg) = (%_ClassOf(arg) === 'String');
113macro IS_BOOLEAN_WRAPPER(arg) = (%_ClassOf(arg) === 'Boolean');
114macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error');
115macro IS_SCRIPT(arg) = (%_ClassOf(arg) === 'Script');
116macro IS_ARGUMENTS(arg) = (%_ClassOf(arg) === 'Arguments');
117macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global');
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000118macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg));
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000119macro FLOOR(arg) = $floor(arg);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000120
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000121# Macro for ECMAScript 5 queries of the type:
122# "Type(O) is object."
lrn@chromium.org34e60782011-09-15 07:25:40 +0000123# This is the same as being either a function or an object in V8 terminology
124# (including proxies).
ricow@chromium.org4980dff2010-07-19 08:33:45 +0000125# In addition, an undetectable object is also included by this.
lrn@chromium.org34e60782011-09-15 07:25:40 +0000126macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg));
127
128# Macro for ECMAScript 5 queries of the type:
129# "IsCallable(O)"
130# We assume here that this is the same as being either a function or a function
131# proxy. That ignores host objects with [[Call]] methods, but in most situations
132# we cannot handle those anyway.
133macro IS_SPEC_FUNCTION(arg) = (%_ClassOf(arg) === 'Function');
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000134
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000135# Indices in bound function info retrieved by %BoundFunctionGetBindings(...).
136const kBoundFunctionIndex = 0;
137const kBoundThisIndex = 1;
138const kBoundArgumentsStartIndex = 2;
139
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000140# Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
141macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000142macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0)));
ricow@chromium.org65fae842010-08-25 15:26:24 +0000143macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg)));
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000144macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
fschneider@chromium.orgb95b98b2010-02-23 10:34:29 +0000145macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));
146macro TO_UINT32(arg) = (arg >>> 0);
147macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg));
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000148macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : NonNumberToNumber(arg));
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000149macro TO_OBJECT_INLINE(arg) = (IS_SPEC_OBJECT(%IS_VAR(arg)) ? arg : ToObject(arg));
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000150macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000151
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000152# Macros implemented in Python.
153python macro CHAR_CODE(str) = ord(str[1]);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000154
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000155# Constants used on an array to implement the properties of the RegExp object.
156const REGEXP_NUMBER_OF_CAPTURES = 0;
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000157const REGEXP_FIRST_CAPTURE = 3;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000158
159# We can't put macros in macros so we use constants here.
160# REGEXP_NUMBER_OF_CAPTURES
161macro NUMBER_OF_CAPTURES(array) = ((array)[0]);
162
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000163# Limit according to ECMA 262 15.9.1.1
164const MAX_TIME_MS = 8640000000000000;
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000165# Limit which is MAX_TIME_MS + msPerMonth.
166const MAX_TIME_BEFORE_UTC = 8640002592000000;
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000167
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000168# Gets the value of a Date object. If arg is not a Date object
169# a type error is thrown.
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +0000170macro CHECK_DATE(arg) = if (%_ClassOf(arg) !== 'Date') ThrowDateTypeError();
171macro LOCAL_DATE_VALUE(arg) = (%_DateField(arg, 0) + %_DateField(arg, 21));
172macro UTC_DATE_VALUE(arg) = (%_DateField(arg, 0));
173
174macro LOCAL_YEAR(arg) = (%_DateField(arg, 1));
175macro LOCAL_MONTH(arg) = (%_DateField(arg, 2));
176macro LOCAL_DAY(arg) = (%_DateField(arg, 3));
177macro LOCAL_WEEKDAY(arg) = (%_DateField(arg, 4));
178macro LOCAL_HOUR(arg) = (%_DateField(arg, 5));
179macro LOCAL_MIN(arg) = (%_DateField(arg, 6));
180macro LOCAL_SEC(arg) = (%_DateField(arg, 7));
181macro LOCAL_MS(arg) = (%_DateField(arg, 8));
182macro LOCAL_DAYS(arg) = (%_DateField(arg, 9));
183macro LOCAL_TIME_IN_DAY(arg) = (%_DateField(arg, 10));
184
185macro UTC_YEAR(arg) = (%_DateField(arg, 11));
186macro UTC_MONTH(arg) = (%_DateField(arg, 12));
187macro UTC_DAY(arg) = (%_DateField(arg, 13));
188macro UTC_WEEKDAY(arg) = (%_DateField(arg, 14));
189macro UTC_HOUR(arg) = (%_DateField(arg, 15));
190macro UTC_MIN(arg) = (%_DateField(arg, 16));
191macro UTC_SEC(arg) = (%_DateField(arg, 17));
192macro UTC_MS(arg) = (%_DateField(arg, 18));
193macro UTC_DAYS(arg) = (%_DateField(arg, 19));
194macro UTC_TIME_IN_DAY(arg) = (%_DateField(arg, 20));
195
196macro TIMEZONE_OFFSET(arg) = (%_DateField(arg, 21));
197
198macro SET_UTC_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 1));
199macro SET_LOCAL_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 0));
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000200
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000201# Last input and last subject of regexp matches.
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +0000202const LAST_SUBJECT_INDEX = 1;
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000203macro LAST_SUBJECT(array) = ((array)[1]);
204macro LAST_INPUT(array) = ((array)[2]);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000205
206# REGEXP_FIRST_CAPTURE
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000207macro CAPTURE(index) = (3 + (index));
208const CAPTURE0 = 3;
209const CAPTURE1 = 4;
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000210
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000211# For the regexp capture override array. This has the same
212# format as the arguments to a function called from
213# String.prototype.replace.
214macro OVERRIDE_MATCH(override) = ((override)[0]);
215macro OVERRIDE_POS(override) = ((override)[(override).length - 2]);
216macro OVERRIDE_SUBJECT(override) = ((override)[(override).length - 1]);
217# 1-based so index of 1 returns the first capture
218macro OVERRIDE_CAPTURE(override, index) = ((override)[(index)]);
219
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000220# PropertyDescriptor return value indices - must match
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000221# PropertyDescriptorIndices in runtime.cc.
222const IS_ACCESSOR_INDEX = 0;
223const VALUE_INDEX = 1;
224const GETTER_INDEX = 2;
225const SETTER_INDEX = 3;
226const WRITABLE_INDEX = 4;
227const ENUMERABLE_INDEX = 5;
228const CONFIGURABLE_INDEX = 6;
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000229
230# For messages.js
231# Matches Script::Type from objects.h
232const TYPE_NATIVE = 0;
233const TYPE_EXTENSION = 1;
234const TYPE_NORMAL = 2;
235
236# Matches Script::CompilationType from objects.h
237const COMPILATION_TYPE_HOST = 0;
238const COMPILATION_TYPE_EVAL = 1;
239const COMPILATION_TYPE_JSON = 2;
240
241# Matches Messages::kNoLineNumberInfo from v8.h
242const kNoLineNumberInfo = 0;