Commit f39707cd authored by domenic's avatar domenic Committed by Commit bot

Use "define" instead of "const" for natives macros

The use of "const" prevented the actual JavaScript const keyword from
functioning as intended.

R=jochen@chromium.org,yangguo@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1110963003

Cr-Commit-Position: refs/heads/master@{#28111}
parent 8a89a4a5
......@@ -28,58 +28,58 @@
# Dictionary that is passed as defines for js2c.py.
# Used for defines that must be defined for all native JS files.
const NONE = 0;
const READ_ONLY = 1;
const DONT_ENUM = 2;
const DONT_DELETE = 4;
const NEW_ONE_BYTE_STRING = true;
const NEW_TWO_BYTE_STRING = false;
define NONE = 0;
define READ_ONLY = 1;
define DONT_ENUM = 2;
define DONT_DELETE = 4;
define NEW_ONE_BYTE_STRING = true;
define NEW_TWO_BYTE_STRING = false;
# Constants used for getter and setter operations.
const GETTER = 0;
const SETTER = 1;
define GETTER = 0;
define SETTER = 1;
const NO_HINT = 0;
const NUMBER_HINT = 1;
const STRING_HINT = 2;
define NO_HINT = 0;
define NUMBER_HINT = 1;
define STRING_HINT = 2;
# For date.js.
const HoursPerDay = 24;
const MinutesPerHour = 60;
const SecondsPerMinute = 60;
const msPerSecond = 1000;
const msPerMinute = 60000;
const msPerHour = 3600000;
const msPerDay = 86400000;
const msPerMonth = 2592000000;
define HoursPerDay = 24;
define MinutesPerHour = 60;
define SecondsPerMinute = 60;
define msPerSecond = 1000;
define msPerMinute = 60000;
define msPerHour = 3600000;
define msPerDay = 86400000;
define msPerMonth = 2592000000;
# Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1).
const kInvalidDate = 'Invalid Date';
const kDayZeroInJulianDay = 2440588;
const kMonthMask = 0x1e0;
const kDayMask = 0x01f;
const kYearShift = 9;
const kMonthShift = 5;
define kInvalidDate = 'Invalid Date';
define kDayZeroInJulianDay = 2440588;
define kMonthMask = 0x1e0;
define kDayMask = 0x01f;
define kYearShift = 9;
define kMonthShift = 5;
# Limits for parts of the date, so that we support all the dates that
# ECMA 262 - 15.9.1.1 requires us to, but at the same time be sure that
# the date (days since 1970) is in SMI range.
const kMinYear = -1000000;
const kMaxYear = 1000000;
const kMinMonth = -10000000;
const kMaxMonth = 10000000;
define kMinYear = -1000000;
define kMaxYear = 1000000;
define kMinMonth = -10000000;
define kMaxMonth = 10000000;
# Safe maximum number of arguments to push to stack, when multiplied by
# pointer size. Used by Function.prototype.apply(), Reflect.apply() and
# Reflect.construct().
const kSafeArgumentsLength = 0x800000;
define kSafeArgumentsLength = 0x800000;
# Strict mode flags for passing to %SetProperty
const kSloppyMode = 0;
const kStrictMode = 1;
define kSloppyMode = 0;
define kStrictMode = 1;
# Native cache ids.
const STRING_TO_REGEXP_CACHE_ID = 0;
define STRING_TO_REGEXP_CACHE_ID = 0;
# Type query macros.
#
......@@ -136,9 +136,9 @@ macro IS_SPEC_FUNCTION(arg) = (%_ClassOf(arg) === 'Function');
macro CHECK_OBJECT_COERCIBLE(arg, functionName) = if (IS_NULL_OR_UNDEFINED(arg) && !IS_UNDETECTABLE(arg)) throw MakeTypeError(kCalledOnNullOrUndefined, functionName);
# Indices in bound function info retrieved by %BoundFunctionGetBindings(...).
const kBoundFunctionIndex = 0;
const kBoundThisIndex = 1;
const kBoundArgumentsStartIndex = 2;
define kBoundFunctionIndex = 0;
define kBoundThisIndex = 1;
define kBoundArgumentsStartIndex = 2;
# Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
......@@ -169,25 +169,25 @@ macro SET_PRIVATE(obj, sym, val) = (obj[sym] = val);
macro DELETE_PRIVATE(obj, sym) = (delete obj[sym]);
# Constants. The compiler constant folds them.
const NAN = $NaN;
const INFINITY = (1/0);
const UNDEFINED = (void 0);
define NAN = $NaN;
define INFINITY = (1/0);
define UNDEFINED = (void 0);
# Macros implemented in Python.
python macro CHAR_CODE(str) = ord(str[1]);
# Constants used on an array to implement the properties of the RegExp object.
const REGEXP_NUMBER_OF_CAPTURES = 0;
const REGEXP_FIRST_CAPTURE = 3;
define REGEXP_NUMBER_OF_CAPTURES = 0;
define REGEXP_FIRST_CAPTURE = 3;
# We can't put macros in macros so we use constants here.
# REGEXP_NUMBER_OF_CAPTURES
macro NUMBER_OF_CAPTURES(array) = ((array)[0]);
# Limit according to ECMA 262 15.9.1.1
const MAX_TIME_MS = 8640000000000000;
define MAX_TIME_MS = 8640000000000000;
# Limit which is MAX_TIME_MS + msPerMonth.
const MAX_TIME_BEFORE_UTC = 8640002592000000;
define MAX_TIME_BEFORE_UTC = 8640002592000000;
# Gets the value of a Date object. If arg is not a Date object
# a type error is thrown.
......@@ -223,14 +223,14 @@ macro SET_UTC_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 1));
macro SET_LOCAL_DATE_VALUE(arg, value) = (%DateSetValue(arg, value, 0));
# Last input and last subject of regexp matches.
const LAST_SUBJECT_INDEX = 1;
define LAST_SUBJECT_INDEX = 1;
macro LAST_SUBJECT(array) = ((array)[1]);
macro LAST_INPUT(array) = ((array)[2]);
# REGEXP_FIRST_CAPTURE
macro CAPTURE(index) = (3 + (index));
const CAPTURE0 = 3;
const CAPTURE1 = 4;
define CAPTURE0 = 3;
define CAPTURE1 = 4;
# For the regexp capture override array. This has the same
# format as the arguments to a function called from
......@@ -243,38 +243,38 @@ macro OVERRIDE_CAPTURE(override, index) = ((override)[(index)]);
# PropertyDescriptor return value indices - must match
# PropertyDescriptorIndices in runtime-object.cc.
const IS_ACCESSOR_INDEX = 0;
const VALUE_INDEX = 1;
const GETTER_INDEX = 2;
const SETTER_INDEX = 3;
const WRITABLE_INDEX = 4;
const ENUMERABLE_INDEX = 5;
const CONFIGURABLE_INDEX = 6;
define IS_ACCESSOR_INDEX = 0;
define VALUE_INDEX = 1;
define GETTER_INDEX = 2;
define SETTER_INDEX = 3;
define WRITABLE_INDEX = 4;
define ENUMERABLE_INDEX = 5;
define CONFIGURABLE_INDEX = 6;
# For messages.js
# Matches Script::Type from objects.h
const TYPE_NATIVE = 0;
const TYPE_EXTENSION = 1;
const TYPE_NORMAL = 2;
define TYPE_NATIVE = 0;
define TYPE_EXTENSION = 1;
define TYPE_NORMAL = 2;
# Matches Script::CompilationType from objects.h
const COMPILATION_TYPE_HOST = 0;
const COMPILATION_TYPE_EVAL = 1;
const COMPILATION_TYPE_JSON = 2;
define COMPILATION_TYPE_HOST = 0;
define COMPILATION_TYPE_EVAL = 1;
define COMPILATION_TYPE_JSON = 2;
# Matches Messages::kNoLineNumberInfo from v8.h
const kNoLineNumberInfo = 0;
define kNoLineNumberInfo = 0;
# Matches PropertyAttributes from property-details.h
const PROPERTY_ATTRIBUTES_NONE = 0;
const PROPERTY_ATTRIBUTES_STRING = 8;
const PROPERTY_ATTRIBUTES_SYMBOLIC = 16;
const PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL = 32;
define PROPERTY_ATTRIBUTES_NONE = 0;
define PROPERTY_ATTRIBUTES_STRING = 8;
define PROPERTY_ATTRIBUTES_SYMBOLIC = 16;
define PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL = 32;
# Use for keys, values and entries iterators.
const ITERATOR_KIND_KEYS = 1;
const ITERATOR_KIND_VALUES = 2;
const ITERATOR_KIND_ENTRIES = 3;
define ITERATOR_KIND_KEYS = 1;
define ITERATOR_KIND_VALUES = 2;
define ITERATOR_KIND_ENTRIES = 3;
macro FIXED_ARRAY_GET(array, index) = (%_FixedArrayGet(array, (index) | 0));
macro FIXED_ARRAY_SET(array, index, value) = (%_FixedArraySet(array, (index) | 0, value));
......@@ -301,9 +301,9 @@ macro ORDERED_HASH_MAP_VALUE_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(tab
macro ORDERED_HASH_MAP_CHAIN_AT(table, entry, numBuckets) = (FIXED_ARRAY_GET(table, ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets) + 2));
# Must match OrderedHashTable::kNotFound.
const NOT_FOUND = -1;
define NOT_FOUND = -1;
# Check whether debug is active.
const DEBUG_IS_ACTIVE = (%_DebugIsActive() != 0);
define DEBUG_IS_ACTIVE = (%_DebugIsActive() != 0);
macro DEBUG_IS_STEPPING(function) = (%_DebugIsActive() != 0 && %DebugCallbackSupportsStepping(function));
macro DEBUG_PREPARE_STEP_IN_IF_STEPPING(function) = if (DEBUG_IS_STEPPING(function)) %DebugPrepareStepInIfStepping(function);
......@@ -36,15 +36,15 @@ var GlobalMath = global.Math;
//-------------------------------------------------------------------
const INVPIO2 = kMath[0];
const PIO2_1 = kMath[1];
const PIO2_1T = kMath[2];
const PIO2_2 = kMath[3];
const PIO2_2T = kMath[4];
const PIO2_3 = kMath[5];
const PIO2_3T = kMath[6];
const PIO4 = kMath[32];
const PIO4LO = kMath[33];
define INVPIO2 = kMath[0];
define PIO2_1 = kMath[1];
define PIO2_1T = kMath[2];
define PIO2_2 = kMath[3];
define PIO2_2T = kMath[4];
define PIO2_3 = kMath[5];
define PIO2_3T = kMath[6];
define PIO4 = kMath[32];
define PIO4LO = kMath[33];
// Compute k and r such that x - k*pi/2 = r where |r| < pi/4. For
// precision, r is returned as two values y0 and y1 such that r = y0 + y1
......@@ -149,12 +149,12 @@ endmacro
// then 3 2
// sin(x) = X + (S1*X + (X *(r-Y/2)+Y))
//
const S1 = -1.66666666666666324348e-01;
const S2 = 8.33333333332248946124e-03;
const S3 = -1.98412698298579493134e-04;
const S4 = 2.75573137070700676789e-06;
const S5 = -2.50507602534068634195e-08;
const S6 = 1.58969099521155010221e-10;
define S1 = -1.66666666666666324348e-01;
define S2 = 8.33333333332248946124e-03;
define S3 = -1.98412698298579493134e-04;
define S4 = 2.75573137070700676789e-06;
define S5 = -2.50507602534068634195e-08;
define S6 = 1.58969099521155010221e-10;
macro RETURN_KERNELSIN(X, Y, SIGN)
var z = X * X;
......@@ -195,12 +195,12 @@ endmacro
// magnitude of the latter is at least a quarter of X*X/2,
// thus, reducing the rounding error in the subtraction.
//
const C1 = 4.16666666666666019037e-02;
const C2 = -1.38888888888741095749e-03;
const C3 = 2.48015872894767294178e-05;
const C4 = -2.75573143513906633035e-07;
const C5 = 2.08757232129817482790e-09;
const C6 = -1.13596475577881948265e-11;
define C1 = 4.16666666666666019037e-02;
define C2 = -1.38888888888741095749e-03;
define C3 = 2.48015872894767294178e-05;
define C4 = -2.75573143513906633035e-07;
define C5 = 2.08757232129817482790e-09;
define C6 = -1.13596475577881948265e-11;
macro RETURN_KERNELCOS(X, Y, SIGN)
var ix = %_DoubleHi(X) & 0x7fffffff;
......@@ -440,14 +440,14 @@ function MathTan(x) {
//
// See HP-15C Advanced Functions Handbook, p.193.
//
const LN2_HI = kMath[34];
const LN2_LO = kMath[35];
const TWO_THIRD = kMath[36];
define LN2_HI = kMath[34];
define LN2_LO = kMath[35];
define TWO_THIRD = kMath[36];
macro KLOG1P(x)
(kMath[37+x])
endmacro
// 2^54
const TWO54 = 18014398509481984;
define TWO54 = 18014398509481984;
function MathLog1p(x) {
x = x * 1; // Convert to number.
......@@ -626,8 +626,8 @@ function MathLog1p(x) {
// For IEEE double
// if x > 7.09782712893383973096e+02 then expm1(x) overflow
//
const KEXPM1_OVERFLOW = kMath[44];
const INVLN2 = kMath[45];
define KEXPM1_OVERFLOW = kMath[44];
define INVLN2 = kMath[45];
macro KEXPM1(x)
(kMath[46+x])
endmacro
......@@ -749,9 +749,9 @@ function MathExpm1(x) {
// sinh(x) is |x| if x is +Infinity, -Infinity, or NaN.
// only sinh(0)=0 is exact for finite x.
//
const KSINH_OVERFLOW = kMath[51];
const TWO_M28 = 3.725290298461914e-9; // 2^-28, empty lower half
const LOG_MAXD = 709.7822265625; // 0x40862e42 00000000, empty lower half
define KSINH_OVERFLOW = kMath[51];
define TWO_M28 = 3.725290298461914e-9; // 2^-28, empty lower half
define LOG_MAXD = 709.7822265625; // 0x40862e42 00000000, empty lower half
function MathSinh(x) {
x = x * 1; // Convert to number.
......@@ -801,7 +801,7 @@ function MathSinh(x) {
// cosh(x) is |x| if x is +INF, -INF, or NaN.
// only cosh(0)=1 is exact for finite x.
//
const KCOSH_OVERFLOW = kMath[51];
define KCOSH_OVERFLOW = kMath[51];
function MathCosh(x) {
x = x * 1; // Convert to number.
......@@ -859,9 +859,9 @@ function MathCosh(x) {
// log10(10**N) = N for N=0,1,...,22.
//
const IVLN10 = kMath[52];
const LOG10_2HI = kMath[53];
const LOG10_2LO = kMath[54];
define IVLN10 = kMath[52];
define LOG10_2HI = kMath[53];
define LOG10_2LO = kMath[54];
function MathLog10(x) {
x = x * 1; // Convert to number.
......@@ -909,8 +909,8 @@ function MathLog10(x) {
// log2(x) = w1 + w2
// where w1 has 53-24 = 29 bits of trailing zeroes.
const DP_H = kMath[64];
const DP_L = kMath[65];
define DP_H = kMath[64];
define DP_L = kMath[65];
// Polynomial coefficients for (3/2)*(log2(x) - 2*s - 2/3*s^3)
macro KLOG2(x)
......@@ -918,11 +918,11 @@ macro KLOG2(x)
endmacro
// cp = 2/(3*ln(2)). Note that cp_h + cp_l is cp, but with more accuracy.
const CP = kMath[61];
const CP_H = kMath[62];
const CP_L = kMath[63];
define CP = kMath[61];
define CP_H = kMath[62];
define CP_L = kMath[63];
// 2^53
const TWO53 = 9007199254740992;
define TWO53 = 9007199254740992;
function MathLog2(x) {
x = x * 1; // Convert to number.
......
......@@ -158,7 +158,7 @@ class PythonMacro:
args.append(mapping[arg])
return str(self.fun(*args))
CONST_PATTERN = re.compile(r'^const\s+([a-zA-Z0-9_]+)\s*=\s*([^;]*);$')
CONST_PATTERN = re.compile(r'^define\s+([a-zA-Z0-9_]+)\s*=\s*([^;]*);$')
MACRO_PATTERN = re.compile(r'^macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]*);$')
PYTHON_MACRO_PATTERN = re.compile(r'^python\s+macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]*);$')
......@@ -240,7 +240,7 @@ def ExpandInlineMacros(lines):
lines = ExpandMacroDefinition(lines, pos, name_pattern, macro, non_expander)
INLINE_CONSTANT_PATTERN = re.compile(r'const\s+([a-zA-Z0-9_]+)\s*=\s*([^;\n]+)[;\n]')
INLINE_CONSTANT_PATTERN = re.compile(r'define\s+([a-zA-Z0-9_]+)\s*=\s*([^;\n]+)[;\n]')
def ExpandInlineConstants(lines):
pos = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment