Changeset 174049 in webkit


Ignore:
Timestamp:
Sep 28, 2014 6:52:42 PM (10 years ago)
Author:
commit-queue@webkit.org
Message:

Simple ES6 feature: Number constructor extras
https://bugs.webkit.org/show_bug.cgi?id=131707

Patch by Diego Pino Garcia <Diego Pino Garcia> on 2014-09-28
Reviewed by Darin Adler.

Source/JavaScriptCore:

  • runtime/CommonIdentifiers.h:
  • runtime/NumberConstructor.cpp:

(JSC::NumberConstructor::finishCreation): Setup constants and
functions.
(JSC::numberConstructorFuncIsFinite): Added.
(JSC::numberConstructorFuncIsInteger): Added.
(JSC::numberConstructorFuncIsNaN): Added.
(JSC::numberConstructorFuncIsSafeInteger): Added.
(JSC::NumberConstructor::getOwnPropertySlot): Deleted.
(JSC::numberConstructorNaNValue): Deleted.
(JSC::numberConstructorNegInfinity): Deleted.
(JSC::numberConstructorPosInfinity): Deleted.
(JSC::numberConstructorMaxValue): Deleted.
(JSC::numberConstructorMinValue): Deleted.

  • runtime/NumberConstructor.h:

LayoutTests:

  • js/Object-getOwnPropertyNames-expected.txt:
  • js/number-constructor-expected.txt: Added.
  • js/number-constructor.html: Added.
  • js/script-tests/Object-getOwnPropertyNames.js:
  • js/script-tests/number-constructor.js: Added.
Location:
trunk
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r174046 r174049  
     12014-09-28  Diego Pino Garcia  <dpino@igalia.com>
     2
     3        Simple ES6 feature: Number constructor extras
     4        https://bugs.webkit.org/show_bug.cgi?id=131707
     5
     6        Reviewed by Darin Adler.
     7
     8        * js/Object-getOwnPropertyNames-expected.txt:
     9        * js/number-constructor-expected.txt: Added.
     10        * js/number-constructor.html: Added.
     11        * js/script-tests/Object-getOwnPropertyNames.js:
     12        * js/script-tests/number-constructor.js: Added.
     13
    1142014-09-28  Sungmann Cho  <sungmann.cho@navercorp.com>
    215
  • trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt

    r173911 r174049  
    5151PASS getSortedOwnPropertyNames(Boolean) is ['length', 'name', 'prototype']
    5252PASS getSortedOwnPropertyNames(Boolean.prototype) is ['constructor', 'toString', 'valueOf']
    53 PASS getSortedOwnPropertyNames(Number) is ['MAX_VALUE', 'MIN_VALUE', 'NEGATIVE_INFINITY', 'NaN', 'POSITIVE_INFINITY', 'length', 'name', 'prototype']
     53PASS getSortedOwnPropertyNames(Number) is ['EPSILON', 'MAX_SAFE_INTEGER', 'MAX_VALUE', 'MIN_SAFE_INTEGER', 'MIN_VALUE', 'NEGATIVE_INFINITY', 'NaN', 'POSITIVE_INFINITY', 'isFinite', 'isInteger', 'isNaN', 'isSafeInteger', 'length', 'name', 'parseFloat', 'parseInt', 'prototype']
    5454PASS getSortedOwnPropertyNames(Number.prototype) is ['clz', 'constructor', 'toExponential', 'toFixed', 'toLocaleString', 'toPrecision', 'toString', 'valueOf']
    5555PASS getSortedOwnPropertyNames(Date) is ['UTC', 'length', 'name', 'now', 'parse', 'prototype']
  • trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js

    r173911 r174049  
    5959    "Boolean": "['length', 'name', 'prototype']",
    6060    "Boolean.prototype": "['constructor', 'toString', 'valueOf']",
    61     "Number": "['MAX_VALUE', 'MIN_VALUE', 'NEGATIVE_INFINITY', 'NaN', 'POSITIVE_INFINITY', 'length', 'name', 'prototype']",
     61    "Number": "['EPSILON', 'MAX_SAFE_INTEGER', 'MAX_VALUE', 'MIN_SAFE_INTEGER', 'MIN_VALUE', 'NEGATIVE_INFINITY', 'NaN', 'POSITIVE_INFINITY', 'isFinite', 'isInteger', 'isNaN', 'isSafeInteger', 'length', 'name', 'parseFloat', 'parseInt', 'prototype']",
    6262    "Number.prototype": "['clz', 'constructor', 'toExponential', 'toFixed', 'toLocaleString', 'toPrecision', 'toString', 'valueOf']",
    6363    "Date": "['UTC', 'length', 'name', 'now', 'parse', 'prototype']",
  • trunk/Source/JavaScriptCore/ChangeLog

    r174036 r174049  
     12014-09-28  Diego Pino Garcia  <dpino@igalia.com>
     2
     3        Simple ES6 feature: Number constructor extras
     4        https://bugs.webkit.org/show_bug.cgi?id=131707
     5
     6        Reviewed by Darin Adler.
     7
     8        * runtime/CommonIdentifiers.h:
     9        * runtime/NumberConstructor.cpp:
     10        (JSC::NumberConstructor::finishCreation): Setup constants and
     11        functions.
     12        (JSC::numberConstructorFuncIsFinite): Added.
     13        (JSC::numberConstructorFuncIsInteger): Added.
     14        (JSC::numberConstructorFuncIsNaN): Added.
     15        (JSC::numberConstructorFuncIsSafeInteger): Added.
     16        (JSC::NumberConstructor::getOwnPropertySlot): Deleted.
     17        (JSC::numberConstructorNaNValue): Deleted.
     18        (JSC::numberConstructorNegInfinity): Deleted.
     19        (JSC::numberConstructorPosInfinity): Deleted.
     20        (JSC::numberConstructorMaxValue): Deleted.
     21        (JSC::numberConstructorMinValue): Deleted.
     22        * runtime/NumberConstructor.h:
     23
    1242014-09-26  Filip Pizlo  <fpizlo@apple.com>
    225
  • trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h

    r173911 r174049  
    119119    macro(instructionCount) \
    120120    macro(isArray) \
     121    macro(isFinite) \
     122    macro(isInteger) \
     123    macro(isNaN) \
    121124    macro(isPrototypeOf) \
     125    macro(isSafeInteger) \
    122126    macro(isView) \
    123127    macro(isWatchpoint) \
     
    141145    macro(osrExits) \
    142146    macro(parse) \
     147    macro(parseFloat) \
     148    macro(parseInt) \
    143149    macro(postMessage) \
    144150    macro(profiledBytecodes) \
  • trunk/Source/JavaScriptCore/runtime/NumberConstructor.cpp

    r173911 r174049  
    2727#include "NumberPrototype.h"
    2828#include "JSCInlines.h"
     29#include "JSGlobalObjectFunctions.h"
    2930
    3031namespace JSC {
    3132
    32 static EncodedJSValue numberConstructorNaNValue(ExecState*, JSObject*, EncodedJSValue, PropertyName);
    33 static EncodedJSValue numberConstructorNegInfinity(ExecState*, JSObject*, EncodedJSValue, PropertyName);
    34 static EncodedJSValue numberConstructorPosInfinity(ExecState*, JSObject*, EncodedJSValue, PropertyName);
    35 static EncodedJSValue numberConstructorMaxValue(ExecState*, JSObject*, EncodedJSValue, PropertyName);
    36 static EncodedJSValue numberConstructorMinValue(ExecState*, JSObject*, EncodedJSValue, PropertyName);
     33static EncodedJSValue JSC_HOST_CALL numberConstructorFuncIsFinite(ExecState*);
     34static EncodedJSValue JSC_HOST_CALL numberConstructorFuncIsInteger(ExecState*);
     35static EncodedJSValue JSC_HOST_CALL numberConstructorFuncIsNaN(ExecState*);
     36static EncodedJSValue JSC_HOST_CALL numberConstructorFuncIsSafeInteger(ExecState*);
    3737
    3838} // namespace JSC
    39 
    40 #include "NumberConstructor.lut.h"
    4139
    4240namespace JSC {
     
    4442STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(NumberConstructor);
    4543
    46 const ClassInfo NumberConstructor::s_info = { "Function", &InternalFunction::s_info, &numberConstructorTable, CREATE_METHOD_TABLE(NumberConstructor) };
    47 
    48 /* Source for NumberConstructor.lut.h
    49 @begin numberConstructorTable
    50    NaN                   numberConstructorNaNValue       DontEnum|DontDelete|ReadOnly
    51    NEGATIVE_INFINITY     numberConstructorNegInfinity    DontEnum|DontDelete|ReadOnly
    52    POSITIVE_INFINITY     numberConstructorPosInfinity    DontEnum|DontDelete|ReadOnly
    53    MAX_VALUE             numberConstructorMaxValue       DontEnum|DontDelete|ReadOnly
    54    MIN_VALUE             numberConstructorMinValue       DontEnum|DontDelete|ReadOnly
    55 @end
    56 */
     44const ClassInfo NumberConstructor::s_info = { "Function", &InternalFunction::s_info, 0, CREATE_METHOD_TABLE(NumberConstructor) };
    5745
    5846NumberConstructor::NumberConstructor(VM& vm, Structure* structure)
     
    7159    // no. of arguments for constructor
    7260    putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
    73 }
    7461
    75 bool NumberConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
    76 {
    77     return getStaticValueSlot<NumberConstructor, InternalFunction>(exec, numberConstructorTable, jsCast<NumberConstructor*>(object), propertyName, slot);
    78 }
     62    putDirectWithoutTransition(vm, Identifier(&vm, "EPSILON"), jsDoubleNumber(std::numeric_limits<double>::epsilon()), DontDelete | DontEnum | ReadOnly);
     63    putDirectWithoutTransition(vm, Identifier(&vm, "MAX_VALUE"), jsDoubleNumber(1.7976931348623157E+308), DontDelete | DontEnum | ReadOnly);
     64    putDirectWithoutTransition(vm, Identifier(&vm, "MIN_VALUE"), jsDoubleNumber(5E-324), DontDelete | DontEnum | ReadOnly);
     65    putDirectWithoutTransition(vm, Identifier(&vm, "MAX_SAFE_INTEGER"), jsDoubleNumber(9007199254740991.0), DontDelete | DontEnum | ReadOnly);
     66    putDirectWithoutTransition(vm, Identifier(&vm, "MIN_SAFE_INTEGER"), jsDoubleNumber(-9007199254740991.0), DontDelete | DontEnum | ReadOnly);
     67    putDirectWithoutTransition(vm, Identifier(&vm, "NEGATIVE_INFINITY"), jsDoubleNumber(-std::numeric_limits<double>::infinity()), DontDelete | DontEnum | ReadOnly);
     68    putDirectWithoutTransition(vm, Identifier(&vm, "POSITIVE_INFINITY"), jsDoubleNumber(std::numeric_limits<double>::infinity()), DontDelete | DontEnum | ReadOnly);
     69    putDirectWithoutTransition(vm, Identifier(&vm, "NaN"), jsNaN(), DontDelete | DontEnum | ReadOnly);
    7970
    80 static EncodedJSValue numberConstructorNaNValue(ExecState*, JSObject*, EncodedJSValue, PropertyName)
    81 {
    82     return JSValue::encode(jsNaN());
    83 }
    84 
    85 static EncodedJSValue numberConstructorNegInfinity(ExecState*, JSObject*, EncodedJSValue, PropertyName)
    86 {
    87     return JSValue::encode(jsNumber(-std::numeric_limits<double>::infinity()));
    88 }
    89 
    90 static EncodedJSValue numberConstructorPosInfinity(ExecState*, JSObject*, EncodedJSValue, PropertyName)
    91 {
    92     return JSValue::encode(jsNumber(std::numeric_limits<double>::infinity()));
    93 }
    94 
    95 static EncodedJSValue numberConstructorMaxValue(ExecState*, JSObject*, EncodedJSValue, PropertyName)
    96 {
    97     return JSValue::encode(jsNumber(1.7976931348623157E+308));
    98 }
    99 
    100 static EncodedJSValue numberConstructorMinValue(ExecState*, JSObject*, EncodedJSValue, PropertyName)
    101 {
    102     return JSValue::encode(jsNumber(5E-324));
     71    putDirectNativeFunctionWithoutTransition(vm, numberPrototype->globalObject(), Identifier(&vm, "isFinite"), 1, numberConstructorFuncIsFinite, NoIntrinsic, DontEnum | Function);
     72    putDirectNativeFunctionWithoutTransition(vm, numberPrototype->globalObject(), Identifier(&vm, "isInteger"), 1, numberConstructorFuncIsInteger, NoIntrinsic, DontEnum | Function);
     73    putDirectNativeFunctionWithoutTransition(vm, numberPrototype->globalObject(), Identifier(&vm, "isNaN"), 1, numberConstructorFuncIsNaN, NoIntrinsic, DontEnum | Function);
     74    putDirectNativeFunctionWithoutTransition(vm, numberPrototype->globalObject(), Identifier(&vm, "isSafeInteger"), 1, numberConstructorFuncIsSafeInteger, NoIntrinsic, DontEnum | Function);
     75    putDirectNativeFunctionWithoutTransition(vm, numberPrototype->globalObject(), Identifier(&vm, "parseFloat"), 1, globalFuncParseFloat, NoIntrinsic, DontEnum | Function);
     76    putDirectNativeFunctionWithoutTransition(vm, numberPrototype->globalObject(), Identifier(&vm, "parseInt"), 1, globalFuncParseInt, NoIntrinsic, DontEnum | Function);
    10377}
    10478
     
    130104}
    131105
     106// ECMA-262 20.1.2.2
     107static EncodedJSValue JSC_HOST_CALL numberConstructorFuncIsFinite(ExecState* exec)
     108{
     109    JSValue argument = exec->argument(0);
     110    return JSValue::encode(jsBoolean(argument.isNumber() && (argument.isInt32() || std::isfinite(argument.asDouble()))));
     111}
     112
     113// ECMA-262 20.1.2.3
     114static EncodedJSValue JSC_HOST_CALL numberConstructorFuncIsInteger(ExecState* exec)
     115{
     116    JSValue argument = exec->argument(0);
     117    bool isInteger;
     118    if (argument.isInt32())
     119        isInteger = true;
     120    else if (!argument.isDouble())
     121        isInteger = false;
     122    else {
     123        double number = argument.asDouble();
     124        isInteger = std::isfinite(number) && trunc(number) == number;
     125    }
     126    return JSValue::encode(jsBoolean(isInteger));
     127}
     128
     129// ECMA-262 20.1.2.4
     130static EncodedJSValue JSC_HOST_CALL numberConstructorFuncIsNaN(ExecState* exec)
     131{
     132    JSValue argument = exec->argument(0);
     133    return JSValue::encode(jsBoolean(argument.isDouble() && std::isnan(argument.asDouble())));
     134}
     135
     136// ECMA-262 20.1.2.5
     137static EncodedJSValue JSC_HOST_CALL numberConstructorFuncIsSafeInteger(ExecState* exec)
     138{
     139    JSValue argument = exec->argument(0);
     140    bool isInteger;
     141    if (argument.isInt32())
     142        isInteger = true;
     143    else if (!argument.isDouble())
     144        isInteger = false;
     145    else {
     146        double number = argument.asDouble();
     147        isInteger = trunc(number) == number && std::abs(number) <= 9007199254740991.0;
     148    }
     149    return JSValue::encode(jsBoolean(isInteger));
     150}
     151
    132152} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/NumberConstructor.h

    r173911 r174049  
    3939    }
    4040
    41     static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
    42     JSValue getValueProperty(ExecState*, int token) const;
    43 
    4441    DECLARE_INFO;
    4542
     
    4845        return Structure::create(vm, globalObject, proto, TypeInfo(ObjectType, StructureFlags), info());
    4946    }
    50 
    51     enum { NaNValue, NegInfinity, PosInfinity, MaxValue, MinValue };
    5247
    5348protected:
Note: See TracChangeset for help on using the changeset viewer.