blob: ba54b2c8962a3f3ceea31e7a0b018fa0b85eaf56 [file] [log] [blame]
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001# Copyright 2006-2008 Google Inc. 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.
29# Used for defines that must be defined for all native js files.
30
31const NONE = 0;
32const READ_ONLY = 1;
33const DONT_ENUM = 2;
34const 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.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000041const kApiTagOffset = 0;
42const kApiPropertyListOffset = 1;
43const kApiSerialNumberOffset = 2;
44const kApiConstructorOffset = 2;
kasper.lund212ac232008-07-16 07:07:30 +000045const 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
52const kFunctionTag = 0;
53const kNewObjectTag = 1;
54
55# For date.js
56const HoursPerDay = 24;
57const MinutesPerHour = 60;
58const SecondsPerMinute = 60;
59const msPerSecond = 1000;
60const msPerMinute = 60000;
61const msPerHour = 3600000;
62const msPerDay = 86400000;
63
64# 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;
71
72# Type query macros
73macro 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');
81macro IS_REGEXP(arg) = (%ClassOf(arg) === 'RegExp');
82macro IS_ARRAY(arg) = (%ClassOf(arg) === 'Array');
83macro IS_DATE(arg) = (%ClassOf(arg) === 'Date');
84macro IS_ERROR(arg) = (%ClassOf(arg) === 'Error');
85macro IS_SCRIPT(arg) = (%ClassOf(arg) === 'Script');
86
87# 'Inline' macros
88# (Make sure arg is evaluated only once via %IS_VAR)
89macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInteger(arg));
90macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInt32(arg));
91
92python macro CHAR_CODE(str) = ord(str[1]);
93
94# Accessors for original global properties that ensure they have been loaded.
95const ORIGINAL_REGEXP = (global.RegExp, $RegExp);
96const ORIGINAL_DATE = (global.Date, $Date);