blob: 69f36c09c050a7f7ddd4c81d969b9901f6c96786 [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.
29# Used for defines that must be defined for all native js files.
30
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;
35
36# Constants used for getter and setter operations.
37const GETTER = 0;
38const SETTER = 1;
39
kasper.lund212ac232008-07-16 07:07:30 +000040# These definitions must match the index of the properties in objects.h.
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000041const kApiTagOffset = 0;
42const kApiPropertyListOffset = 1;
43const kApiSerialNumberOffset = 2;
44const kApiConstructorOffset = 2;
45const kApiPrototypeTemplateOffset = 5;
46const kApiParentTemplateOffset = 6;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000047
48const NO_HINT = 0;
49const NUMBER_HINT = 1;
50const STRING_HINT = 2;
51
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000052const kFunctionTag = 0;
53const kNewObjectTag = 1;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000054
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000055# For date.js.
56const HoursPerDay = 24;
57const MinutesPerHour = 60;
58const SecondsPerMinute = 60;
59const msPerSecond = 1000;
60const msPerMinute = 60000;
61const msPerHour = 3600000;
62const msPerDay = 86400000;
ager@chromium.orgeadaf222009-06-16 09:43:10 +000063const msPerMonth = 2592000000;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000064
ager@chromium.org32912102009-01-16 10:38:43 +000065# For apinatives.js
66const kUninitialized = -1;
67
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000068# 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;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000075
ager@chromium.orgce5e87b2010-03-10 10:24:18 +000076# 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
ricow@chromium.orgc9c80822010-04-21 08:22:37 +000086# Native cache ids.
87const STRING_TO_REGEXP_CACHE_ID = 0;
88
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000089# Type query macros.
fschneider@chromium.orgb95b98b2010-02-23 10:34:29 +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'.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000094macro IS_NULL(arg) = (arg === null);
95macro IS_NULL_OR_UNDEFINED(arg) = (arg == null);
96macro IS_UNDEFINED(arg) = (typeof(arg) === 'undefined');
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000097macro IS_NUMBER(arg) = (typeof(arg) === 'number');
98macro IS_STRING(arg) = (typeof(arg) === 'string');
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000099macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean');
ager@chromium.org6141cbe2009-11-20 12:14:52 +0000100macro IS_OBJECT(arg) = (%_IsObject(arg));
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000101macro IS_ARRAY(arg) = (%_IsArray(arg));
ager@chromium.org6141cbe2009-11-20 12:14:52 +0000102macro IS_FUNCTION(arg) = (%_IsFunction(arg));
fschneider@chromium.orgb95b98b2010-02-23 10:34:29 +0000103macro IS_REGEXP(arg) = (%_IsRegExp(arg));
kasperl@chromium.org2abc4502009-07-02 07:00:29 +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');
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000112macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg));
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000113macro FLOOR(arg) = $floor(arg);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000114
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000115# 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.
ricow@chromium.org4980dff2010-07-19 08:33:45 +0000118# In addition, an undetectable object is also included by this.
119macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg));
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000120
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000121# Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
122macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +0000123macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || arg - arg == 0);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000124macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg)));
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000125macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
fschneider@chromium.orgb95b98b2010-02-23 10:34:29 +0000126macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));
127macro TO_UINT32(arg) = (arg >>> 0);
128macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg));
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000129macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : NonNumberToNumber(arg));
fschneider@chromium.orgb95b98b2010-02-23 10:34:29 +0000130
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000131
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000132# Macros implemented in Python.
133python macro CHAR_CODE(str) = ord(str[1]);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000134
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000135# Constants used on an array to implement the properties of the RegExp object.
136const REGEXP_NUMBER_OF_CAPTURES = 0;
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000137const REGEXP_FIRST_CAPTURE = 3;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000138
139# We can't put macros in macros so we use constants here.
140# REGEXP_NUMBER_OF_CAPTURES
141macro NUMBER_OF_CAPTURES(array) = ((array)[0]);
142
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000143# Limit according to ECMA 262 15.9.1.1
144const MAX_TIME_MS = 8640000000000000;
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000145# Limit which is MAX_TIME_MS + msPerMonth.
146const MAX_TIME_BEFORE_UTC = 8640002592000000;
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000147
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000148# Gets the value of a Date object. If arg is not a Date object
149# a type error is thrown.
150macro DATE_VALUE(arg) = (%_ClassOf(arg) === 'Date' ? %_ValueOf(arg) : ThrowDateTypeError());
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000151macro DAY(time) = ($floor(time / 86400000));
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000152macro NAN_OR_DATE_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : DateFromTime(time));
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000153macro HOUR_FROM_TIME(time) = (Modulo($floor(time / 3600000), 24));
154macro MIN_FROM_TIME(time) = (Modulo($floor(time / 60000), 60));
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000155macro NAN_OR_MIN_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : MIN_FROM_TIME(time));
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000156macro SEC_FROM_TIME(time) = (Modulo($floor(time / 1000), 60));
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000157macro NAN_OR_SEC_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : SEC_FROM_TIME(time));
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000158macro MS_FROM_TIME(time) = (Modulo(time, 1000));
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000159macro NAN_OR_MS_FROM_TIME(time) = (NUMBER_IS_NAN(time) ? time : MS_FROM_TIME(time));
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000160
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000161# Last input and last subject of regexp matches.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000162macro LAST_SUBJECT(array) = ((array)[1]);
163macro LAST_INPUT(array) = ((array)[2]);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000164
165# REGEXP_FIRST_CAPTURE
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000166macro CAPTURE(index) = (3 + (index));
167const CAPTURE0 = 3;
168const CAPTURE1 = 4;
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000169
170# PropertyDescriptor return value indices - must match
171# PropertyDescriptorIndices in runtime.cc.
172const IS_ACCESSOR_INDEX = 0;
173const VALUE_INDEX = 1;
174const GETTER_INDEX = 2;
175const SETTER_INDEX = 3;
176const WRITABLE_INDEX = 4;
177const ENUMERABLE_INDEX = 5;
178const CONFIGURABLE_INDEX = 6;