The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / src / macros.py @ 40c0f755

History | View | Annotate | Download (4.76 KB)

1
# 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.
29
# Used for defines that must be defined for all native js files.
30

    
31
const NONE        = 0;
32
const READ_ONLY   = 1;
33
const DONT_ENUM   = 2;
34
const DONT_DELETE = 4;
35

    
36
# Constants used for getter and setter operations.
37
const GETTER = 0;
38
const SETTER = 1;
39

    
40
# These definitions must match the index of the properties in objects.h.
41
const kApiTagOffset               = 0;
42
const kApiPropertyListOffset      = 1;
43
const kApiSerialNumberOffset      = 2;
44
const kApiConstructorOffset       = 2;
45
const kApiPrototypeTemplateOffset = 5;
46
const kApiParentTemplateOffset    = 6;
47

    
48
const NO_HINT     = 0;
49
const NUMBER_HINT = 1;
50
const STRING_HINT = 2;
51

    
52
const kFunctionTag  = 0;
53
const kNewObjectTag = 1;
54

    
55
# For date.js.
56
const HoursPerDay      = 24;
57
const MinutesPerHour   = 60;
58
const SecondsPerMinute = 60;
59
const msPerSecond      = 1000;
60
const msPerMinute      = 60000;
61
const msPerHour        = 3600000;
62
const msPerDay         = 86400000;
63

    
64
# For apinatives.js
65
const kUninitialized = -1;
66

    
67
# Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1).
68
const kInvalidDate        = 'Invalid Date';
69
const kDayZeroInJulianDay = 2440588;
70
const kMonthMask          = 0x1e0;
71
const kDayMask            = 0x01f;
72
const kYearShift          = 9;
73
const kMonthShift         = 5;
74

    
75
# Type query macros.
76
macro IS_NULL(arg)              = (arg === null);
77
macro IS_NULL_OR_UNDEFINED(arg) = (arg == null);
78
macro IS_UNDEFINED(arg)         = (typeof(arg) === 'undefined');
79
macro IS_FUNCTION(arg)          = (typeof(arg) === 'function');
80
macro IS_NUMBER(arg)            = (typeof(arg) === 'number');
81
macro IS_STRING(arg)            = (typeof(arg) === 'string');
82
macro IS_OBJECT(arg)            = (typeof(arg) === 'object');
83
macro IS_BOOLEAN(arg)           = (typeof(arg) === 'boolean');
84
macro IS_REGEXP(arg)            = %HasRegExpClass(arg);
85
macro IS_ARRAY(arg)             = %HasArrayClass(arg);
86
macro IS_DATE(arg)              = %HasDateClass(arg);
87
macro IS_ERROR(arg)             = (%ClassOf(arg) === 'Error');
88
macro IS_SCRIPT(arg)            = (%ClassOf(arg) === 'Script');
89
macro FLOOR(arg)                = %Math_floor(arg);
90

    
91
# Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
92
macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
93
macro TO_INTEGER(arg)    = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInteger(arg));
94
macro TO_INT32(arg)      = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInt32(arg));
95

    
96
# Macros implemented in Python.
97
python macro CHAR_CODE(str) = ord(str[1]);
98

    
99
# Accessors for original global properties that ensure they have been loaded.
100
const ORIGINAL_REGEXP = (global.RegExp, $RegExp);
101
const ORIGINAL_DATE   = (global.Date, $Date);
102

    
103
# Constants used on an array to implement the properties of the RegExp object.
104
const REGEXP_NUMBER_OF_CAPTURES = 0;
105
const REGEXP_FIRST_CAPTURE = 3;
106

    
107
# We can't put macros in macros so we use constants here.
108
# REGEXP_NUMBER_OF_CAPTURES
109
macro NUMBER_OF_CAPTURES(array) = ((array)[0]);
110

    
111
# Last input and last subject are after the captures so we can omit them on
112
# results returned from global searches.  Beware - these evaluate their
113
# arguments twice.
114
macro LAST_SUBJECT(array) = ((array)[1]);
115
macro LAST_INPUT(array) = ((array)[2]);
116

    
117
# REGEXP_FIRST_CAPTURE
118
macro CAPTURE(index) = (3 + (index));
119
const CAPTURE0 = 3;
120
const CAPTURE1 = 4;