Changeset 171278 in webkit


Ignore:
Timestamp:
Jul 20, 2014 9:16:57 AM (10 years ago)
Author:
commit-queue@webkit.org
Message:

ES6: Implement Math.sign()
https://bugs.webkit.org/show_bug.cgi?id=134980

Patch by Diego Pino Garcia <Diego Pino Garcia> on 2014-07-20
Reviewed by Darin Adler.

Source/JavaScriptCore:

  • runtime/MathObject.cpp:

(JSC::MathObject::finishCreation):
(JSC::mathProtoFuncSign):

LayoutTests:

  • js/script-tests/Object-getOwnPropertyNames.js:
  • js/script-tests/math.js:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r171263 r171278  
     12014-07-20  Diego Pino Garcia  <dpino@igalia.com>
     2
     3        ES6: Implement Math.sign()
     4        https://bugs.webkit.org/show_bug.cgi?id=134980
     5
     6        Reviewed by Darin Adler.
     7
     8        * js/script-tests/Object-getOwnPropertyNames.js:
     9        * js/script-tests/math.js:
     10
    1112014-07-19  Carlos Alberto Lopez Perez  <clopez@igalia.com>
    212
  • trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt

    r167797 r171278  
    5959PASS getSortedOwnPropertyNames(Error) is ['length', 'name', 'prototype']
    6060PASS getSortedOwnPropertyNames(Error.prototype) is ['constructor', 'message', 'name', 'toString']
    61 PASS getSortedOwnPropertyNames(Math) is ['E','LN10','LN2','LOG10E','LOG2E','PI','SQRT1_2','SQRT2','abs','acos','acosh','asin','asinh','atan','atan2','atanh','cbrt','ceil','cos','cosh','exp','expm1','floor','fround','hypot','imul','log','log10','log1p','log2','max','min','pow','random','round','sin','sinh','sqrt','tan','tanh','trunc']
     61PASS getSortedOwnPropertyNames(Math) is ['E','LN10','LN2','LOG10E','LOG2E','PI','SQRT1_2','SQRT2','abs','acos','acosh','asin','asinh','atan','atan2','atanh','cbrt','ceil','cos','cosh','exp','expm1','floor','fround','hypot','imul','log','log10','log1p','log2','max','min','pow','random','round','sign','sin','sinh','sqrt','tan','tanh','trunc']
    6262PASS getSortedOwnPropertyNames(JSON) is ['parse', 'stringify']
    6363PASS globalPropertyNames.indexOf('NaN') != -1 is true
  • trunk/LayoutTests/js/math-expected.txt

    r165795 r171278  
    182182PASS Math.round(Infinity) is Infinity
    183183PASS Math.round(-Infinity) is -Infinity
     184PASS Math.sign(NaN) is NaN
     185PASS Math.sign('string') is NaN
     186PASS Math.sign([1, 2, 3]) is NaN
     187PASS Math.sign({}) is NaN
     188PASS Math.sign(0) is 0
     189PASS Math.sign(-0) is -0
     190PASS Math.sign(-1) is -1
     191PASS Math.sign(1) is 1
     192PASS Math.sign(0.1) is 1
     193PASS Math.sign(-0.1) is -1
     194PASS Math.sign(10000) is 1
     195PASS Math.sign(-10000) is -1
     196PASS Math.sign(Number.MIN_VALUE) is 1
     197PASS Math.sign(-Number.MIN_VALUE) is -1
     198PASS Math.sign(Number.MAX_VALUE) is 1
     199PASS Math.sign(-Number.MAX_VALUE) is -1
     200PASS Math.sign(Infinity) is 1
     201PASS Math.sign(-Infinity) is -1
    184202PASS Math.sin(NaN) is NaN
    185203PASS Math.sin(0) is 0
  • trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js

    r167797 r171278  
    6767    "Error": "['length', 'name', 'prototype']",
    6868    "Error.prototype": "['constructor', 'message', 'name', 'toString']",
    69     "Math": "['E','LN10','LN2','LOG10E','LOG2E','PI','SQRT1_2','SQRT2','abs','acos','acosh','asin','asinh','atan','atan2','atanh','cbrt','ceil','cos','cosh','exp','expm1','floor','fround','hypot','imul','log','log10','log1p','log2','max','min','pow','random','round','sin','sinh','sqrt','tan','tanh','trunc']",
     69    "Math": "['E','LN10','LN2','LOG10E','LOG2E','PI','SQRT1_2','SQRT2','abs','acos','acosh','asin','asinh','atan','atan2','atanh','cbrt','ceil','cos','cosh','exp','expm1','floor','fround','hypot','imul','log','log10','log1p','log2','max','min','pow','random','round','sign','sin','sinh','sqrt','tan','tanh','trunc']",
    7070    "JSON": "['parse', 'stringify']"
    7171};
  • trunk/LayoutTests/js/script-tests/math.js

    r165795 r171278  
    255255shouldBe("Math.round(-Infinity)", "-Infinity");
    256256
     257shouldBe("Math.sign(NaN)", "NaN");
     258shouldBe("Math.sign('string')", "NaN");
     259shouldBe("Math.sign([1, 2, 3])", "NaN");
     260shouldBe("Math.sign({})", "NaN");
     261shouldBe("Math.sign(0)", "0");
     262shouldBe("Math.sign(-0)", "-0");
     263shouldBe("Math.sign(-1)", "-1");
     264shouldBe("Math.sign(1)", "1");
     265shouldBe("Math.sign(0.1)", "1");
     266shouldBe("Math.sign(-0.1)", "-1");
     267shouldBe("Math.sign(10000)", "1");
     268shouldBe("Math.sign(-10000)", "-1");
     269shouldBe("Math.sign(Number.MIN_VALUE)", "1");
     270shouldBe("Math.sign(-Number.MIN_VALUE)", "-1");
     271shouldBe("Math.sign(Number.MAX_VALUE)", "1");
     272shouldBe("Math.sign(-Number.MAX_VALUE)", "-1");
     273shouldBe("Math.sign(Infinity)", "1");
     274shouldBe("Math.sign(-Infinity)", "-1");
     275
    257276shouldBe("Math.sin(NaN)", "NaN");
    258277shouldBe("Math.sin(0)", "0");
  • trunk/Source/JavaScriptCore/ChangeLog

    r171241 r171278  
     12014-07-20  Diego Pino Garcia  <dpino@igalia.com>
     2
     3        ES6: Implement Math.sign()
     4        https://bugs.webkit.org/show_bug.cgi?id=134980
     5
     6        Reviewed by Darin Adler.
     7
     8        * runtime/MathObject.cpp:
     9        (JSC::MathObject::finishCreation):
     10        (JSC::mathProtoFuncSign):
     11
    1122014-07-18  Filip Pizlo  <fpizlo@apple.com>
    213
  • trunk/Source/JavaScriptCore/runtime/MathObject.cpp

    r167394 r171278  
    6262static EncodedJSValue JSC_HOST_CALL mathProtoFuncRandom(ExecState*);
    6363static EncodedJSValue JSC_HOST_CALL mathProtoFuncRound(ExecState*);
     64static EncodedJSValue JSC_HOST_CALL mathProtoFuncSign(ExecState*);
    6465static EncodedJSValue JSC_HOST_CALL mathProtoFuncSin(ExecState*);
    6566static EncodedJSValue JSC_HOST_CALL mathProtoFuncSinh(ExecState*);
     
    121122    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "random"), 0, mathProtoFuncRandom, NoIntrinsic, DontEnum | Function);
    122123    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "round"), 1, mathProtoFuncRound, RoundIntrinsic, DontEnum | Function);
     124    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "sign"), 1, mathProtoFuncSign, NoIntrinsic, DontEnum | Function);
    123125    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "sin"), 1, mathProtoFuncSin, SinIntrinsic, DontEnum | Function);
    124126    putDirectNativeFunctionWithoutTransition(vm, globalObject, Identifier(&vm, "sinh"), 1, mathProtoFuncSinh, NoIntrinsic, DontEnum | Function);
     
    302304    double integer = ceil(arg);
    303305    return JSValue::encode(jsNumber(integer - (integer - arg > 0.5)));
     306}
     307
     308EncodedJSValue JSC_HOST_CALL mathProtoFuncSign(ExecState* exec)
     309{
     310    double arg = exec->argument(0).toNumber(exec);
     311    if (std::isnan(arg))
     312        return JSValue::encode(jsNaN());
     313    if (!arg)
     314        return JSValue::encode(std::signbit(arg) ? jsNumber(-0.0) : jsNumber(0));
     315    return JSValue::encode(jsNumber(std::signbit(arg) ? -1 : 1));
    304316}
    305317
Note: See TracChangeset for help on using the changeset viewer.