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 @ f230a1cf

History | View | Annotate | Download (10.7 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
const NEW_ONE_BYTE_STRING = true;
36
const NEW_TWO_BYTE_STRING = false;
37

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

    
42
# These definitions must match the index of the properties in objects.h.
43
const kApiTagOffset                 = 0;
44
const kApiPropertyListOffset        = 1;
45
const kApiSerialNumberOffset        = 3;
46
const kApiConstructorOffset         = 3;
47
const kApiPrototypeTemplateOffset   = 5;
48
const kApiParentTemplateOffset      = 6;
49
const kApiFlagOffset                = 14;
50

    
51
const NO_HINT     = 0;
52
const NUMBER_HINT = 1;
53
const STRING_HINT = 2;
54

    
55
const kFunctionTag  = 0;
56
const kNewObjectTag = 1;
57

    
58
# For date.js.
59
const HoursPerDay      = 24;
60
const MinutesPerHour   = 60;
61
const SecondsPerMinute = 60;
62
const msPerSecond      = 1000;
63
const msPerMinute      = 60000;
64
const msPerHour        = 3600000;
65
const msPerDay         = 86400000;
66
const msPerMonth       = 2592000000;
67

    
68
# For apinatives.js
69
const kUninitialized = -1;
70
const kReadOnlyPrototypeBit = 3;
71
const kRemovePrototypeBit = 4;  # For FunctionTemplateInfo, matches objects.h
72
const kDoNotCacheBit = 5;  # For FunctionTemplateInfo, matches objects.h
73

    
74
# Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1).
75
const kInvalidDate        = 'Invalid Date';
76
const kDayZeroInJulianDay = 2440588;
77
const kMonthMask          = 0x1e0;
78
const kDayMask            = 0x01f;
79
const kYearShift          = 9;
80
const kMonthShift         = 5;
81

    
82
# 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.
85
const kMinYear  = -1000000;
86
const kMaxYear  = 1000000;
87
const kMinMonth = -10000000;
88
const kMaxMonth = 10000000;
89

    
90
# Native cache ids.
91
const STRING_TO_REGEXP_CACHE_ID = 0;
92

    
93
# Type query macros.
94
#
95
# Note: We have special support for typeof(foo) === 'bar' in the compiler.
96
#       It will *not* generate a runtime typeof call for the most important
97
#       values of 'bar'.
98
macro IS_NULL(arg)              = (arg === null);
99
macro IS_NULL_OR_UNDEFINED(arg) = (arg == null);
100
macro IS_UNDEFINED(arg)         = (typeof(arg) === 'undefined');
101
macro IS_NUMBER(arg)            = (typeof(arg) === 'number');
102
macro IS_STRING(arg)            = (typeof(arg) === 'string');
103
macro IS_BOOLEAN(arg)           = (typeof(arg) === 'boolean');
104
macro IS_SYMBOL(arg)            = (typeof(arg) === 'symbol');
105
macro IS_OBJECT(arg)            = (%_IsObject(arg));
106
macro IS_ARRAY(arg)             = (%_IsArray(arg));
107
macro IS_FUNCTION(arg)          = (%_IsFunction(arg));
108
macro IS_REGEXP(arg)            = (%_IsRegExp(arg));
109
macro IS_SET(arg)               = (%_ClassOf(arg) === 'Set');
110
macro IS_MAP(arg)               = (%_ClassOf(arg) === 'Map');
111
macro IS_WEAKMAP(arg)           = (%_ClassOf(arg) === 'WeakMap');
112
macro IS_WEAKSET(arg)           = (%_ClassOf(arg) === 'WeakSet');
113
macro IS_DATE(arg)              = (%_ClassOf(arg) === 'Date');
114
macro IS_NUMBER_WRAPPER(arg)    = (%_ClassOf(arg) === 'Number');
115
macro IS_STRING_WRAPPER(arg)    = (%_ClassOf(arg) === 'String');
116
macro IS_SYMBOL_WRAPPER(arg)    = (%_ClassOf(arg) === 'Symbol');
117
macro IS_BOOLEAN_WRAPPER(arg)   = (%_ClassOf(arg) === 'Boolean');
118
macro IS_ERROR(arg)             = (%_ClassOf(arg) === 'Error');
119
macro IS_SCRIPT(arg)            = (%_ClassOf(arg) === 'Script');
120
macro IS_ARGUMENTS(arg)         = (%_ClassOf(arg) === 'Arguments');
121
macro IS_GLOBAL(arg)            = (%_ClassOf(arg) === 'global');
122
macro IS_ARRAYBUFFER(arg)       = (%_ClassOf(arg) === 'ArrayBuffer');
123
macro IS_DATAVIEW(arg)          = (%_ClassOf(arg) === 'DataView');
124
macro IS_GENERATOR(arg)         = (%_ClassOf(arg) === 'Generator');
125
macro IS_UNDETECTABLE(arg)      = (%_IsUndetectableObject(arg));
126
macro FLOOR(arg)                = $floor(arg);
127

    
128
# Macro for ECMAScript 5 queries of the type:
129
# "Type(O) is object."
130
# This is the same as being either a function or an object in V8 terminology
131
# (including proxies).
132
# In addition, an undetectable object is also included by this.
133
macro IS_SPEC_OBJECT(arg)   = (%_IsSpecObject(arg));
134

    
135
# Macro for ECMAScript 5 queries of the type:
136
# "IsCallable(O)"
137
# We assume here that this is the same as being either a function or a function
138
# proxy. That ignores host objects with [[Call]] methods, but in most situations
139
# we cannot handle those anyway.
140
macro IS_SPEC_FUNCTION(arg) = (%_ClassOf(arg) === 'Function');
141

    
142
# Indices in bound function info retrieved by %BoundFunctionGetBindings(...).
143
const kBoundFunctionIndex = 0;
144
const kBoundThisIndex = 1;
145
const kBoundArgumentsStartIndex = 2;
146

    
147
# Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
148
macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
149
macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0)));
150
macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg)));
151
macro TO_INTEGER_FOR_SIDE_EFFECT(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToNumber(arg));
152
macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
153
macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));
154
macro TO_UINT32(arg) = (arg >>> 0);
155
macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg));
156
macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : NonNumberToNumber(arg));
157
macro TO_OBJECT_INLINE(arg) = (IS_SPEC_OBJECT(%IS_VAR(arg)) ? arg : ToObject(arg));
158
macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null");
159

    
160
# Constants.  The compiler constant folds them.
161
const NAN = $NaN;
162
const INFINITY = (1/0);
163
const UNDEFINED = (void 0);
164

    
165
# Macros implemented in Python.
166
python macro CHAR_CODE(str) = ord(str[1]);
167

    
168
# Constants used on an array to implement the properties of the RegExp object.
169
const REGEXP_NUMBER_OF_CAPTURES = 0;
170
const REGEXP_FIRST_CAPTURE = 3;
171

    
172
# We can't put macros in macros so we use constants here.
173
# REGEXP_NUMBER_OF_CAPTURES
174
macro NUMBER_OF_CAPTURES(array) = ((array)[0]);
175

    
176
# Limit according to ECMA 262 15.9.1.1
177
const MAX_TIME_MS = 8640000000000000;
178
# Limit which is MAX_TIME_MS + msPerMonth.
179
const MAX_TIME_BEFORE_UTC = 8640002592000000;
180

    
181
# Gets the value of a Date object. If arg is not a Date object
182
# a type error is thrown.
183
macro CHECK_DATE(arg) = if (%_ClassOf(arg) !== 'Date') ThrowDateTypeError();
184
macro LOCAL_DATE_VALUE(arg) = (%_DateField(arg, 0) + %_DateField(arg, 21));
185
macro UTC_DATE_VALUE(arg)    = (%_DateField(arg, 0));
186

    
187
macro LOCAL_YEAR(arg)        = (%_DateField(arg, 1));
188
macro LOCAL_MONTH(arg)       = (%_DateField(arg, 2));
189
macro LOCAL_DAY(arg)         = (%_DateField(arg, 3));
190
macro LOCAL_WEEKDAY(arg)     = (%_DateField(arg, 4));
191
macro LOCAL_HOUR(arg)        = (%_DateField(arg, 5));
192
macro LOCAL_MIN(arg)         = (%_DateField(arg, 6));
193
macro LOCAL_SEC(arg)         = (%_DateField(arg, 7));
194
macro LOCAL_MS(arg)          = (%_DateField(arg, 8));
195
macro LOCAL_DAYS(arg)        = (%_DateField(arg, 9));
196
macro LOCAL_TIME_IN_DAY(arg) = (%_DateField(arg, 10));
197

    
198
macro UTC_YEAR(arg)        = (%_DateField(arg, 11));
199
macro UTC_MONTH(arg)       = (%_DateField(arg, 12));
200
macro UTC_DAY(arg)         = (%_DateField(arg, 13));
201
macro UTC_WEEKDAY(arg)     = (%_DateField(arg, 14));
202
macro UTC_HOUR(arg)        = (%_DateField(arg, 15));
203
macro UTC_MIN(arg)         = (%_DateField(arg, 16));
204
macro UTC_SEC(arg)         = (%_DateField(arg, 17));
205
macro UTC_MS(arg)          = (%_DateField(arg, 18));
206
macro UTC_DAYS(arg)        = (%_DateField(arg, 19));
207
macro UTC_TIME_IN_DAY(arg) = (%_DateField(arg, 20));
208

    
209
macro TIMEZONE_OFFSET(arg)   = (%_DateField(arg, 21));
210

    
211
macro SET_UTC_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 1));
212
macro SET_LOCAL_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 0));
213

    
214
# Last input and last subject of regexp matches.
215
const LAST_SUBJECT_INDEX = 1;
216
macro LAST_SUBJECT(array) = ((array)[1]);
217
macro LAST_INPUT(array) = ((array)[2]);
218

    
219
# REGEXP_FIRST_CAPTURE
220
macro CAPTURE(index) = (3 + (index));
221
const CAPTURE0 = 3;
222
const CAPTURE1 = 4;
223

    
224
# For the regexp capture override array.  This has the same
225
# format as the arguments to a function called from
226
# String.prototype.replace.
227
macro OVERRIDE_MATCH(override) = ((override)[0]);
228
macro OVERRIDE_POS(override) = ((override)[(override).length - 2]);
229
macro OVERRIDE_SUBJECT(override) = ((override)[(override).length - 1]);
230
# 1-based so index of 1 returns the first capture
231
macro OVERRIDE_CAPTURE(override, index) = ((override)[(index)]);
232

    
233
# PropertyDescriptor return value indices - must match
234
# PropertyDescriptorIndices in runtime.cc.
235
const IS_ACCESSOR_INDEX = 0;
236
const VALUE_INDEX = 1;
237
const GETTER_INDEX = 2;
238
const SETTER_INDEX = 3;
239
const WRITABLE_INDEX = 4;
240
const ENUMERABLE_INDEX = 5;
241
const CONFIGURABLE_INDEX = 6;
242

    
243
# For messages.js
244
# Matches Script::Type from objects.h
245
const TYPE_NATIVE = 0;
246
const TYPE_EXTENSION = 1;
247
const TYPE_NORMAL = 2;
248

    
249
# Matches Script::CompilationType from objects.h
250
const COMPILATION_TYPE_HOST = 0;
251
const COMPILATION_TYPE_EVAL = 1;
252
const COMPILATION_TYPE_JSON = 2;
253

    
254
# Matches Messages::kNoLineNumberInfo from v8.h
255
const kNoLineNumberInfo = 0;