blob: b3ff0fcf11fb1888c7c9059c4df45b21cec8dfda [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;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000035const NEW_ONE_BYTE_STRING = true;
36const NEW_TWO_BYTE_STRING = false;
Steve Blocka7e24c12009-10-30 11:49:00 +000037
38# Constants used for getter and setter operations.
39const GETTER = 0;
40const SETTER = 1;
41
42# These definitions must match the index of the properties in objects.h.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000043const kApiTagOffset = 0;
44const kApiPropertyListOffset = 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045const kApiSerialNumberOffset = 3;
46const kApiConstructorOffset = 3;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000047const kApiPrototypeTemplateOffset = 5;
48const kApiParentTemplateOffset = 6;
Ben Murdoch69a99ed2011-11-30 16:03:39 +000049const kApiFlagOffset = 14;
Steve Blocka7e24c12009-10-30 11:49:00 +000050
51const NO_HINT = 0;
52const NUMBER_HINT = 1;
53const STRING_HINT = 2;
54
55const kFunctionTag = 0;
56const kNewObjectTag = 1;
57
58# For date.js.
59const HoursPerDay = 24;
60const MinutesPerHour = 60;
61const SecondsPerMinute = 60;
62const msPerSecond = 1000;
63const msPerMinute = 60000;
64const msPerHour = 3600000;
65const msPerDay = 86400000;
66const msPerMonth = 2592000000;
67
68# For apinatives.js
69const kUninitialized = -1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000070const kReadOnlyPrototypeBit = 3;
71const kRemovePrototypeBit = 4; # For FunctionTemplateInfo, matches objects.h
72const kDoNotCacheBit = 5; # For FunctionTemplateInfo, matches objects.h
Steve Blocka7e24c12009-10-30 11:49:00 +000073
74# Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1).
75const kInvalidDate = 'Invalid Date';
76const kDayZeroInJulianDay = 2440588;
77const kMonthMask = 0x1e0;
78const kDayMask = 0x01f;
79const kYearShift = 9;
80const kMonthShift = 5;
81
Steve Block6ded16b2010-05-10 14:33:55 +010082# Limits for parts of the date, so that we support all the dates that
83# ECMA 262 - 15.9.1.1 requires us to, but at the same time be sure that
84# the date (days since 1970) is in SMI range.
85const kMinYear = -1000000;
86const kMaxYear = 1000000;
87const kMinMonth = -10000000;
88const kMaxMonth = 10000000;
Steve Block6ded16b2010-05-10 14:33:55 +010089
Ben Murdochb8a8cc12014-11-26 15:28:44 +000090# Strict mode flags for passing to %SetProperty
91const kSloppyMode = 0;
92const kStrictMode = 1;
93
Steve Block6ded16b2010-05-10 14:33:55 +010094# Native cache ids.
95const STRING_TO_REGEXP_CACHE_ID = 0;
96
Steve Blocka7e24c12009-10-30 11:49:00 +000097# Type query macros.
Andrei Popescu402d9372010-02-26 13:31:12 +000098#
99# Note: We have special support for typeof(foo) === 'bar' in the compiler.
100# It will *not* generate a runtime typeof call for the most important
101# values of 'bar'.
Steve Blocka7e24c12009-10-30 11:49:00 +0000102macro IS_NULL(arg) = (arg === null);
103macro IS_NULL_OR_UNDEFINED(arg) = (arg == null);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000104macro IS_UNDEFINED(arg) = (arg === (void 0));
Steve Blocka7e24c12009-10-30 11:49:00 +0000105macro IS_NUMBER(arg) = (typeof(arg) === 'number');
106macro IS_STRING(arg) = (typeof(arg) === 'string');
Steve Blocka7e24c12009-10-30 11:49:00 +0000107macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean');
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000108macro IS_SYMBOL(arg) = (typeof(arg) === 'symbol');
Steve Blockd0582a62009-12-15 09:54:21 +0000109macro IS_OBJECT(arg) = (%_IsObject(arg));
Steve Blocka7e24c12009-10-30 11:49:00 +0000110macro IS_ARRAY(arg) = (%_IsArray(arg));
Steve Blockd0582a62009-12-15 09:54:21 +0000111macro IS_FUNCTION(arg) = (%_IsFunction(arg));
Andrei Popescu402d9372010-02-26 13:31:12 +0000112macro IS_REGEXP(arg) = (%_IsRegExp(arg));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100113macro IS_SET(arg) = (%_ClassOf(arg) === 'Set');
114macro IS_MAP(arg) = (%_ClassOf(arg) === 'Map');
115macro IS_WEAKMAP(arg) = (%_ClassOf(arg) === 'WeakMap');
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000116macro IS_WEAKSET(arg) = (%_ClassOf(arg) === 'WeakSet');
Steve Blocka7e24c12009-10-30 11:49:00 +0000117macro IS_DATE(arg) = (%_ClassOf(arg) === 'Date');
118macro IS_NUMBER_WRAPPER(arg) = (%_ClassOf(arg) === 'Number');
119macro IS_STRING_WRAPPER(arg) = (%_ClassOf(arg) === 'String');
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000120macro IS_SYMBOL_WRAPPER(arg) = (%_ClassOf(arg) === 'Symbol');
Steve Blocka7e24c12009-10-30 11:49:00 +0000121macro IS_BOOLEAN_WRAPPER(arg) = (%_ClassOf(arg) === 'Boolean');
122macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error');
123macro IS_SCRIPT(arg) = (%_ClassOf(arg) === 'Script');
124macro IS_ARGUMENTS(arg) = (%_ClassOf(arg) === 'Arguments');
125macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global');
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000126macro IS_ARRAYBUFFER(arg) = (%_ClassOf(arg) === 'ArrayBuffer');
127macro IS_DATAVIEW(arg) = (%_ClassOf(arg) === 'DataView');
128macro IS_GENERATOR(arg) = (%_ClassOf(arg) === 'Generator');
129macro IS_SET_ITERATOR(arg) = (%_ClassOf(arg) === 'Set Iterator');
130macro IS_MAP_ITERATOR(arg) = (%_ClassOf(arg) === 'Map Iterator');
Leon Clarked91b9f72010-01-27 17:25:45 +0000131macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg));
Leon Clarkee46be812010-01-19 14:06:41 +0000132macro FLOOR(arg) = $floor(arg);
Steve Blocka7e24c12009-10-30 11:49:00 +0000133
Kristian Monsen25f61362010-05-21 11:50:48 +0100134# Macro for ECMAScript 5 queries of the type:
135# "Type(O) is object."
Ben Murdoch589d6972011-11-30 16:04:58 +0000136# This is the same as being either a function or an object in V8 terminology
137# (including proxies).
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100138# In addition, an undetectable object is also included by this.
Ben Murdoch589d6972011-11-30 16:04:58 +0000139macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg));
140
141# Macro for ECMAScript 5 queries of the type:
142# "IsCallable(O)"
143# We assume here that this is the same as being either a function or a function
144# proxy. That ignores host objects with [[Call]] methods, but in most situations
145# we cannot handle those anyway.
146macro IS_SPEC_FUNCTION(arg) = (%_ClassOf(arg) === 'Function');
Kristian Monsen25f61362010-05-21 11:50:48 +0100147
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000148# Macro for ES6 CheckObjectCoercible
149# Will throw a TypeError of the form "[functionName] called on null or undefined".
150macro CHECK_OBJECT_COERCIBLE(arg, functionName) = if (IS_NULL_OR_UNDEFINED(arg) && !IS_UNDETECTABLE(arg)) throw MakeTypeError('called_on_null_or_undefined', [functionName]);
151
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100152# Indices in bound function info retrieved by %BoundFunctionGetBindings(...).
153const kBoundFunctionIndex = 0;
154const kBoundThisIndex = 1;
155const kBoundArgumentsStartIndex = 2;
156
Steve Blocka7e24c12009-10-30 11:49:00 +0000157# Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
158macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
Ben Murdoch589d6972011-11-30 16:04:58 +0000159macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0)));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100160macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000161macro TO_INTEGER_FOR_SIDE_EFFECT(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToNumber(arg));
Steve Block8defd9f2010-07-08 12:39:36 +0100162macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
Andrei Popescu402d9372010-02-26 13:31:12 +0000163macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));
164macro TO_UINT32(arg) = (arg >>> 0);
165macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg));
Ben Murdoch086aeea2011-05-13 15:57:08 +0100166macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : NonNumberToNumber(arg));
Ben Murdoch257744e2011-11-30 15:57:28 +0000167macro TO_OBJECT_INLINE(arg) = (IS_SPEC_OBJECT(%IS_VAR(arg)) ? arg : ToObject(arg));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000168macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000169macro HAS_OWN_PROPERTY(obj, index) = (%_CallFunction(obj, index, ObjectHasOwnProperty));
170
171# Private names.
172# GET_PRIVATE should only be used if the property is known to exists on obj
173# itself (it should really use %GetOwnProperty, but that would be way slower).
174macro GLOBAL_PRIVATE(name) = (%CreateGlobalPrivateOwnSymbol(name));
175macro NEW_PRIVATE_OWN(name) = (%CreatePrivateOwnSymbol(name));
176macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym));
177macro HAS_PRIVATE(obj, sym) = (%HasOwnProperty(obj, sym));
178macro HAS_DEFINED_PRIVATE(obj, sym) = (!IS_UNDEFINED(obj[sym]));
179macro GET_PRIVATE(obj, sym) = (obj[sym]);
180macro SET_PRIVATE(obj, sym, val) = (obj[sym] = val);
181macro DELETE_PRIVATE(obj, sym) = (delete obj[sym]);
182
183# Constants. The compiler constant folds them.
184const NAN = $NaN;
185const INFINITY = (1/0);
186const UNDEFINED = (void 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000187
188# Macros implemented in Python.
189python macro CHAR_CODE(str) = ord(str[1]);
190
Steve Blocka7e24c12009-10-30 11:49:00 +0000191# Constants used on an array to implement the properties of the RegExp object.
192const REGEXP_NUMBER_OF_CAPTURES = 0;
193const REGEXP_FIRST_CAPTURE = 3;
194
195# We can't put macros in macros so we use constants here.
196# REGEXP_NUMBER_OF_CAPTURES
197macro NUMBER_OF_CAPTURES(array) = ((array)[0]);
198
Steve Block6ded16b2010-05-10 14:33:55 +0100199# Limit according to ECMA 262 15.9.1.1
200const MAX_TIME_MS = 8640000000000000;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100201# Limit which is MAX_TIME_MS + msPerMonth.
202const MAX_TIME_BEFORE_UTC = 8640002592000000;
Steve Block6ded16b2010-05-10 14:33:55 +0100203
Steve Blocka7e24c12009-10-30 11:49:00 +0000204# Gets the value of a Date object. If arg is not a Date object
205# a type error is thrown.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100206macro CHECK_DATE(arg) = if (%_ClassOf(arg) !== 'Date') ThrowDateTypeError();
207macro LOCAL_DATE_VALUE(arg) = (%_DateField(arg, 0) + %_DateField(arg, 21));
208macro UTC_DATE_VALUE(arg) = (%_DateField(arg, 0));
209
210macro LOCAL_YEAR(arg) = (%_DateField(arg, 1));
211macro LOCAL_MONTH(arg) = (%_DateField(arg, 2));
212macro LOCAL_DAY(arg) = (%_DateField(arg, 3));
213macro LOCAL_WEEKDAY(arg) = (%_DateField(arg, 4));
214macro LOCAL_HOUR(arg) = (%_DateField(arg, 5));
215macro LOCAL_MIN(arg) = (%_DateField(arg, 6));
216macro LOCAL_SEC(arg) = (%_DateField(arg, 7));
217macro LOCAL_MS(arg) = (%_DateField(arg, 8));
218macro LOCAL_DAYS(arg) = (%_DateField(arg, 9));
219macro LOCAL_TIME_IN_DAY(arg) = (%_DateField(arg, 10));
220
221macro UTC_YEAR(arg) = (%_DateField(arg, 11));
222macro UTC_MONTH(arg) = (%_DateField(arg, 12));
223macro UTC_DAY(arg) = (%_DateField(arg, 13));
224macro UTC_WEEKDAY(arg) = (%_DateField(arg, 14));
225macro UTC_HOUR(arg) = (%_DateField(arg, 15));
226macro UTC_MIN(arg) = (%_DateField(arg, 16));
227macro UTC_SEC(arg) = (%_DateField(arg, 17));
228macro UTC_MS(arg) = (%_DateField(arg, 18));
229macro UTC_DAYS(arg) = (%_DateField(arg, 19));
230macro UTC_TIME_IN_DAY(arg) = (%_DateField(arg, 20));
231
232macro TIMEZONE_OFFSET(arg) = (%_DateField(arg, 21));
233
234macro SET_UTC_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 1));
235macro SET_LOCAL_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 0));
Steve Blocka7e24c12009-10-30 11:49:00 +0000236
Steve Block3ce2e202009-11-05 08:53:23 +0000237# Last input and last subject of regexp matches.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000238const LAST_SUBJECT_INDEX = 1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000239macro LAST_SUBJECT(array) = ((array)[1]);
240macro LAST_INPUT(array) = ((array)[2]);
241
242# REGEXP_FIRST_CAPTURE
243macro CAPTURE(index) = (3 + (index));
244const CAPTURE0 = 3;
245const CAPTURE1 = 4;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100246
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000247# For the regexp capture override array. This has the same
248# format as the arguments to a function called from
249# String.prototype.replace.
250macro OVERRIDE_MATCH(override) = ((override)[0]);
251macro OVERRIDE_POS(override) = ((override)[(override).length - 2]);
252macro OVERRIDE_SUBJECT(override) = ((override)[(override).length - 1]);
253# 1-based so index of 1 returns the first capture
254macro OVERRIDE_CAPTURE(override, index) = ((override)[(index)]);
255
Ben Murdoch589d6972011-11-30 16:04:58 +0000256# PropertyDescriptor return value indices - must match
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100257# PropertyDescriptorIndices in runtime.cc.
258const IS_ACCESSOR_INDEX = 0;
259const VALUE_INDEX = 1;
260const GETTER_INDEX = 2;
261const SETTER_INDEX = 3;
262const WRITABLE_INDEX = 4;
263const ENUMERABLE_INDEX = 5;
264const CONFIGURABLE_INDEX = 6;
Ben Murdoch589d6972011-11-30 16:04:58 +0000265
266# For messages.js
267# Matches Script::Type from objects.h
268const TYPE_NATIVE = 0;
269const TYPE_EXTENSION = 1;
270const TYPE_NORMAL = 2;
271
272# Matches Script::CompilationType from objects.h
273const COMPILATION_TYPE_HOST = 0;
274const COMPILATION_TYPE_EVAL = 1;
275const COMPILATION_TYPE_JSON = 2;
276
277# Matches Messages::kNoLineNumberInfo from v8.h
278const kNoLineNumberInfo = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000279
280# Matches PropertyAttributes from property-details.h
281const PROPERTY_ATTRIBUTES_NONE = 0;
282const PROPERTY_ATTRIBUTES_STRING = 8;
283const PROPERTY_ATTRIBUTES_SYMBOLIC = 16;
284const PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL = 32;
285
286# Use for keys, values and entries iterators.
287const ITERATOR_KIND_KEYS = 1;
288const ITERATOR_KIND_VALUES = 2;
289const ITERATOR_KIND_ENTRIES = 3;
290
291# Check whether debug is active.
292const DEBUG_IS_ACTIVE = (%_DebugIsActive() != 0);