blob: 5a7606a76d82f0f15b440f5674155094217c79cc [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001# Copyright 2006-2008 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;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000063
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000064# Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1).
65const kInvalidDate = 'Invalid Date';
66const kDayZeroInJulianDay = 2440588;
67const kMonthMask = 0x1e0;
68const kDayMask = 0x01f;
69const kYearShift = 9;
70const kMonthShift = 5;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000071
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000072# Type query macros.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000073macro IS_NULL(arg) = (arg === null);
74macro IS_NULL_OR_UNDEFINED(arg) = (arg == null);
75macro IS_UNDEFINED(arg) = (typeof(arg) === 'undefined');
76macro IS_FUNCTION(arg) = (typeof(arg) === 'function');
77macro IS_NUMBER(arg) = (typeof(arg) === 'number');
78macro IS_STRING(arg) = (typeof(arg) === 'string');
79macro IS_OBJECT(arg) = (typeof(arg) === 'object');
80macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean');
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +000081macro IS_REGEXP(arg) = %HasRegExpClass(arg);
82macro IS_ARRAY(arg) = %HasArrayClass(arg);
83macro IS_DATE(arg) = %HasDateClass(arg);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000084macro IS_ERROR(arg) = (%ClassOf(arg) === 'Error');
85macro IS_SCRIPT(arg) = (%ClassOf(arg) === 'Script');
ager@chromium.org7c537e22008-10-16 08:43:32 +000086macro FLOOR(arg) = %Math_floor(arg);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000087
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000088# Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
89macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
90macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInteger(arg));
91macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInt32(arg));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000092
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000093# Macros implemented in Python.
94python macro CHAR_CODE(str) = ord(str[1]);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000095
96# Accessors for original global properties that ensure they have been loaded.
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000097const ORIGINAL_REGEXP = (global.RegExp, $RegExp);
98const ORIGINAL_DATE = (global.Date, $Date);