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 31define NONE = 0; 32define READ_ONLY = 1; 33define DONT_ENUM = 2; 34define DONT_DELETE = 4; 35 36# 2^32 - 1 37define kMaxUint32 = 4294967295; 38 39# Type query macros. 40# 41# Note: We have special support for typeof(foo) === 'bar' in the compiler. 42# It will *not* generate a runtime typeof call for the most important 43# values of 'bar'. 44macro IS_ARRAY(arg) = (%_IsArray(arg)); 45macro IS_NULL(arg) = (arg === null); 46macro IS_NULL_OR_UNDEFINED(arg) = (arg == null); 47macro IS_NUMBER(arg) = (typeof(arg) === 'number'); 48macro IS_STRING(arg) = (typeof(arg) === 'string'); 49macro IS_SYMBOL(arg) = (typeof(arg) === 'symbol'); 50macro IS_UNDEFINED(arg) = (arg === (void 0)); 51 52# Macro for ES queries of the type: "Type(O) is Object." 53macro IS_RECEIVER(arg) = (%_IsJSReceiver(arg)); 54 55# Macro for ES queries of the type: "IsCallable(O)" 56macro IS_CALLABLE(arg) = (typeof(arg) === 'function'); 57 58# Macro for ES RequireObjectCoercible 59# https://tc39.github.io/ecma262/#sec-requireobjectcoercible 60# Throws a TypeError of the form "[functionName] called on null or undefined". 61macro REQUIRE_OBJECT_COERCIBLE(arg, functionName) = if (IS_NULL(%IS_VAR(arg)) || IS_UNDEFINED(arg)) throw %make_type_error(kCalledOnNullOrUndefined, functionName); 62 63# Inline macros. Use %IS_VAR to make sure arg is evaluated only once. 64macro TO_BOOLEAN(arg) = (!!(arg)); 65macro TO_INTEGER(arg) = (%_ToInteger(arg)); 66macro TO_LENGTH(arg) = (%_ToLength(arg)); 67macro TO_STRING(arg) = (%_ToString(arg)); 68macro TO_NUMBER(arg) = (%_ToNumber(arg)); 69macro TO_OBJECT(arg) = (%_ToObject(arg)); 70macro HAS_OWN_PROPERTY(obj, key) = (%_Call(ObjectHasOwnProperty, obj, key)); 71 72macro DEFINE_METHODS_LEN(obj, class_def, len) = %DefineMethodsInternal(obj, class class_def, len); 73macro DEFINE_METHOD_LEN(obj, method_def, len) = %DefineMethodsInternal(obj, class { method_def }, len); 74macro DEFINE_METHODS(obj, class_def) = DEFINE_METHODS_LEN(obj, class_def, -1); 75macro DEFINE_METHOD(obj, method_def) = DEFINE_METHOD_LEN(obj, method_def, -1); 76 77# Constants. The compiler constant folds them. 78define INFINITY = (1/0); 79define UNDEFINED = (void 0); 80 81# This should be kept consistent with Intl::Type. 82define NUMBER_FORMAT_TYPE = 0; 83define COLLATOR_TYPE = 1; 84define DATE_TIME_FORMAT_TYPE = 2; 85define PLURAL_RULES_TYPE = 3; 86define BREAK_ITERATOR_TYPE = 4; 87define LOCALE_TYPE = 5; 88