blob: c75f0ea48753b680f150fd4a132dd2de0f086309 [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
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000076# Type query macros.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000077macro IS_NULL(arg) = (arg === null);
78macro IS_NULL_OR_UNDEFINED(arg) = (arg == null);
79macro IS_UNDEFINED(arg) = (typeof(arg) === 'undefined');
80macro IS_FUNCTION(arg) = (typeof(arg) === 'function');
81macro IS_NUMBER(arg) = (typeof(arg) === 'number');
82macro IS_STRING(arg) = (typeof(arg) === 'string');
83macro IS_OBJECT(arg) = (typeof(arg) === 'object');
84macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean');
kasperl@chromium.org2abc4502009-07-02 07:00:29 +000085macro IS_ARRAY(arg) = (%_IsArray(arg));
86macro IS_REGEXP(arg) = (%_ClassOf(arg) === 'RegExp');
87macro IS_DATE(arg) = (%_ClassOf(arg) === 'Date');
88macro IS_NUMBER_WRAPPER(arg) = (%_ClassOf(arg) === 'Number');
89macro IS_STRING_WRAPPER(arg) = (%_ClassOf(arg) === 'String');
90macro IS_BOOLEAN_WRAPPER(arg) = (%_ClassOf(arg) === 'Boolean');
91macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error');
92macro IS_SCRIPT(arg) = (%_ClassOf(arg) === 'Script');
93macro IS_ARGUMENTS(arg) = (%_ClassOf(arg) === 'Arguments');
94macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global');
ager@chromium.org7c537e22008-10-16 08:43:32 +000095macro FLOOR(arg) = %Math_floor(arg);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000096
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000097# Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
98macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
99macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInteger(arg));
100macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInt32(arg));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000101
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000102# Macros implemented in Python.
103python macro CHAR_CODE(str) = ord(str[1]);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000104
105# Accessors for original global properties that ensure they have been loaded.
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000106const ORIGINAL_REGEXP = (global.RegExp, $RegExp);
107const ORIGINAL_DATE = (global.Date, $Date);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000108
109# Constants used on an array to implement the properties of the RegExp object.
110const REGEXP_NUMBER_OF_CAPTURES = 0;
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000111const REGEXP_FIRST_CAPTURE = 3;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000112
113# We can't put macros in macros so we use constants here.
114# REGEXP_NUMBER_OF_CAPTURES
115macro NUMBER_OF_CAPTURES(array) = ((array)[0]);
116
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000117# Gets the value of a Date object. If arg is not a Date object
118# a type error is thrown.
119macro DATE_VALUE(arg) = (%_ClassOf(arg) === 'Date' ? %_ValueOf(arg) : ThrowDateTypeError());
120
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000121# Last input and last subject are after the captures so we can omit them on
122# results returned from global searches. Beware - these evaluate their
123# arguments twice.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000124macro LAST_SUBJECT(array) = ((array)[1]);
125macro LAST_INPUT(array) = ((array)[2]);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000126
127# REGEXP_FIRST_CAPTURE
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000128macro CAPTURE(index) = (3 + (index));
129const CAPTURE0 = 3;
130const CAPTURE1 = 4;