Changeset 198469 in webkit


Ignore:
Timestamp:
Mar 19, 2016, 11:13:42 AM (9 years ago)
Author:
mark.lam@apple.com
Message:

ES6 spec requires that ErrorPrototype not be an Error object.
https://bugs.webkit.org/show_bug.cgi?id=155680

Reviewed by Michael Saboff.

Source/JavaScriptCore:

The ES6 spec states that Error.prototype should not be an instance of Error:
https://tc39.github.io/ecma262/#sec-properties-of-the-error-prototype-object

"The Error prototype object is an ordinary object. It is not an Error instance
and does not have an ErrorData internal slot."

This patch changes ErrorPrototype to conform to the above specification.

  • runtime/ErrorConstructor.cpp:

(JSC::ErrorConstructor::finishCreation):

  • runtime/ErrorPrototype.cpp:

(JSC::ErrorPrototype::ErrorPrototype):
(JSC::ErrorPrototype::finishCreation):
(JSC::ErrorPrototype::getOwnPropertySlot):

  • runtime/ErrorPrototype.h:

(JSC::ErrorPrototype::create):

  • runtime/NativeErrorConstructor.cpp:

(JSC::NativeErrorConstructor::finishCreation):

  • runtime/NativeErrorPrototype.cpp:

(JSC::NativeErrorPrototype::NativeErrorPrototype):
(JSC::NativeErrorPrototype::finishCreation):

  • runtime/NativeErrorPrototype.h:

(JSC::NativeErrorPrototype::create):

  • updated to no longer need a JSGlobalObject argument.
  • tests/es6/miscellaneous_built-in_prototypes_are_not_instances.js:
  • updated to match the kangax version of this test.

LayoutTests:

Updated the appropriate tests to expect the toString() value of Error.prototype
to now be "[object Object]" instead of "[object Error]". Also rebased the test
results accordingly.

  • fast/dom/DOMException/prototype-object-expected.txt:
  • fast/dom/DOMException/prototype-object.html:
  • js/dom/native-error-prototype-expected.txt:
  • js/dom/script-tests/native-error-prototype.js:
  • sputnik/Conformance/15_Native_Objects/15.11_Error/15.11.4/S15.11.4_A2.html:
Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r198467 r198469  
     12016-03-19  Mark Lam  <mark.lam@apple.com>
     2
     3        ES6 spec requires that ErrorPrototype not be an Error object.
     4        https://bugs.webkit.org/show_bug.cgi?id=155680
     5
     6        Reviewed by Michael Saboff.
     7
     8        Updated the appropriate tests to expect the toString() value of Error.prototype
     9        to now be "[object Object]" instead of "[object Error]".  Also rebased the test
     10        results accordingly.
     11
     12        * fast/dom/DOMException/prototype-object-expected.txt:
     13        * fast/dom/DOMException/prototype-object.html:
     14        * js/dom/native-error-prototype-expected.txt:
     15        * js/dom/script-tests/native-error-prototype.js:
     16        * sputnik/Conformance/15_Native_Objects/15.11_Error/15.11.4/S15.11.4_A2.html:
     17
    1182016-03-18  Daniel Bates  <dabates@apple.com>
    219
  • trunk/LayoutTests/fast/dom/DOMException/prototype-object-expected.txt

    r196392 r198469  
    77PASS Object.prototype.toString.call(e) is "[object DOMException]"
    88PASS Object.prototype.toString.call(e.__proto__) is "[object DOMExceptionPrototype]"
    9 PASS Object.prototype.toString.call(e.__proto__.__proto__) is "[object Error]"
     9PASS Object.prototype.toString.call(e.__proto__.__proto__) is "[object Object]"
    1010PASS e.constructor.toString() is "function DOMException() {\n    [native code]\n}"
    1111PASS e instanceof DOMException is true
  • trunk/LayoutTests/fast/dom/DOMException/prototype-object.html

    r196392 r198469  
    1616shouldBeEqualToString("Object.prototype.toString.call(e)", "[object DOMException]");
    1717shouldBeEqualToString("Object.prototype.toString.call(e.__proto__)", "[object DOMExceptionPrototype]");
    18 shouldBeEqualToString("Object.prototype.toString.call(e.__proto__.__proto__)", "[object Error]");
     18shouldBeEqualToString("Object.prototype.toString.call(e.__proto__.__proto__)", "[object Object]");
    1919shouldBeEqualToString("e.constructor.toString()", "function DOMException() {\n    [native code]\n}");
    2020shouldBeTrue("e instanceof DOMException");
  • trunk/LayoutTests/js/dom/native-error-prototype-expected.txt

    r156066 r198469  
    44
    55
    6 PASS ({}).toString.call(Error.prototype) is "[object Error]"
    7 PASS ({}).toString.call(RangeError.prototype) is "[object Error]"
     6PASS ({}).toString.call(Error.prototype) is "[object Object]"
     7PASS ({}).toString.call(RangeError.prototype) is "[object Object]"
    88PASS err.toString() is "message"
    99PASS err.hasOwnProperty('message') is false
  • trunk/LayoutTests/js/dom/script-tests/native-error-prototype.js

    r156066 r198469  
    33);
    44
    5 shouldBe("({}).toString.call(Error.prototype)", '"[object Error]"');
    6 shouldBe("({}).toString.call(RangeError.prototype)", '"[object Error]"');
     5shouldBe("({}).toString.call(Error.prototype)", '"[object Object]"');
     6shouldBe("({}).toString.call(RangeError.prototype)", '"[object Object]"');
    77
    88var err = new Error("message");
  • trunk/LayoutTests/sputnik/Conformance/15_Native_Objects/15.11_Error/15.11.4/S15.11.4_A2.html

    r120489 r198469  
    7878//////////////////////////////////////////////////////////////////////////////
    7979//CHECK#1
    80 if (__tostr !== "[object Error]") {
    81         testFailed('#1: Error.prototype.toString=Object.prototype.toString; __tostr = Error.prototype.toString(); __tostr === "[object Error]". Actual: '+__tostr );
     80if (__tostr !== "[object Object]") {
     81        testFailed('#1: Error.prototype.toString=Object.prototype.toString; __tostr = Error.prototype.toString(); __tostr === "[object Object]". Actual: '+__tostr );
    8282}
    8383//
  • trunk/Source/JavaScriptCore/ChangeLog

    r198458 r198469  
     12016-03-19  Mark Lam  <mark.lam@apple.com>
     2
     3        ES6 spec requires that ErrorPrototype not be an Error object.
     4        https://bugs.webkit.org/show_bug.cgi?id=155680
     5
     6        Reviewed by Michael Saboff.
     7
     8        The ES6 spec states that Error.prototype should not be an instance of Error:
     9        https://tc39.github.io/ecma262/#sec-properties-of-the-error-prototype-object
     10
     11        "The Error prototype object is an ordinary object. It is not an Error instance
     12        and does not have an [[ErrorData]] internal slot."
     13
     14        This patch changes ErrorPrototype to conform to the above specification.
     15
     16        * runtime/ErrorConstructor.cpp:
     17        (JSC::ErrorConstructor::finishCreation):
     18        * runtime/ErrorPrototype.cpp:
     19        (JSC::ErrorPrototype::ErrorPrototype):
     20        (JSC::ErrorPrototype::finishCreation):
     21        (JSC::ErrorPrototype::getOwnPropertySlot):
     22        * runtime/ErrorPrototype.h:
     23        (JSC::ErrorPrototype::create):
     24
     25        * runtime/NativeErrorConstructor.cpp:
     26        (JSC::NativeErrorConstructor::finishCreation):
     27        * runtime/NativeErrorPrototype.cpp:
     28        (JSC::NativeErrorPrototype::NativeErrorPrototype):
     29        (JSC::NativeErrorPrototype::finishCreation):
     30        * runtime/NativeErrorPrototype.h:
     31        (JSC::NativeErrorPrototype::create):
     32        - updated to no longer need a JSGlobalObject argument.
     33
     34        * tests/es6/miscellaneous_built-in_prototypes_are_not_instances.js:
     35        - updated to match the kangax version of this test.
     36
    1372016-03-18  Benjamin Poulain  <bpoulain@apple.com>
    238
  • trunk/Source/JavaScriptCore/runtime/ErrorConstructor.cpp

    r197614 r198469  
    4141void ErrorConstructor::finishCreation(VM& vm, ErrorPrototype* errorPrototype)
    4242{
    43     Base::finishCreation(vm, errorPrototype->classInfo()->className);
     43    Base::finishCreation(vm, ASCIILiteral("Error"));
    4444    // ECMA 15.11.3.1 Error.prototype
    4545    putDirectWithoutTransition(vm, vm.propertyNames->prototype, errorPrototype, DontEnum | DontDelete | ReadOnly);
  • trunk/Source/JavaScriptCore/runtime/ErrorPrototype.cpp

    r182495 r198469  
    11/*
    22 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
    3  *  Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
     3 *  Copyright (C) 2003, 2008, 2016 Apple Inc. All rights reserved.
    44 *
    55 *  This library is free software; you can redistribute it and/or
     
    4242namespace JSC {
    4343
    44 const ClassInfo ErrorPrototype::s_info = { "Error", &ErrorInstance::s_info, &errorPrototypeTable, CREATE_METHOD_TABLE(ErrorPrototype) };
     44const ClassInfo ErrorPrototype::s_info = { "Object", &Base::s_info, &errorPrototypeTable, CREATE_METHOD_TABLE(ErrorPrototype) };
    4545
    4646/* Source for ErrorPrototype.lut.h
     
    5151
    5252ErrorPrototype::ErrorPrototype(VM& vm, Structure* structure)
    53     : ErrorInstance(vm, structure)
     53    : JSNonFinalObject(vm, structure)
    5454{
    5555}
    5656
    57 void ErrorPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
     57void ErrorPrototype::finishCreation(VM& vm)
    5858{
    59     Base::finishCreation(globalObject->globalExec(), vm, "");
     59    Base::finishCreation(vm);
    6060    ASSERT(inherits(info()));
    6161    putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("Error"))), DontEnum);
     62    putDirect(vm, vm.propertyNames->message, jsEmptyString(&vm), DontEnum);
    6263}
    6364
  • trunk/Source/JavaScriptCore/runtime/ErrorPrototype.h

    r182747 r198469  
    11/*
    22 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
    3  *  Copyright (C) 2008 Apple Inc. All rights reserved.
     3 *  Copyright (C) 2008, 2016 Apple Inc. All rights reserved.
    44 *
    55 *  This library is free software; you can redistribute it and/or
     
    2222#define ErrorPrototype_h
    2323
    24 #include "ErrorInstance.h"
     24#include "JSObject.h"
    2525
    2626namespace JSC {
     
    2828class ObjectPrototype;
    2929
    30 class ErrorPrototype : public ErrorInstance {
     30class ErrorPrototype : public JSNonFinalObject {
    3131public:
    32     typedef ErrorInstance Base;
     32    typedef JSNonFinalObject Base;
    3333    static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot;
    3434
    35     static ErrorPrototype* create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
     35    static ErrorPrototype* create(VM& vm, JSGlobalObject*, Structure* structure)
    3636    {
    3737        ErrorPrototype* prototype = new (NotNull, allocateCell<ErrorPrototype>(vm.heap)) ErrorPrototype(vm, structure);
    38         prototype->finishCreation(vm, globalObject);
     38        prototype->finishCreation(vm);
    3939        return prototype;
    4040    }
     
    4949protected:
    5050    ErrorPrototype(VM&, Structure*);
    51     void finishCreation(VM&, JSGlobalObject*);
     51    void finishCreation(VM&);
    5252
    5353private:
  • trunk/Source/JavaScriptCore/runtime/NativeErrorConstructor.cpp

    r197614 r198469  
    4444    ASSERT(inherits(info()));
    4545   
    46     NativeErrorPrototype* prototype = NativeErrorPrototype::create(vm, globalObject, prototypeStructure, name, this);
     46    NativeErrorPrototype* prototype = NativeErrorPrototype::create(vm, prototypeStructure, name, this);
    4747   
    4848    putDirect(vm, vm.propertyNames->length, jsNumber(1), DontDelete | ReadOnly | DontEnum); // ECMA 15.11.7.5
  • trunk/Source/JavaScriptCore/runtime/NativeErrorPrototype.cpp

    r163844 r198469  
    11/*
    22 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
    3  *  Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
     3 *  Copyright (C) 2003, 2008, 2016 Apple Inc. All rights reserved.
    44 *
    55 *  This library is free software; you can redistribute it and/or
     
    3434}
    3535
    36 void NativeErrorPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject, const WTF::String& nameAndMessage, NativeErrorConstructor* constructor)
     36void NativeErrorPrototype::finishCreation(VM& vm, const WTF::String& nameAndMessage, NativeErrorConstructor* constructor)
    3737{
    38     Base::finishCreation(vm, globalObject);
     38    Base::finishCreation(vm);
    3939    putDirect(vm, vm.propertyNames->name, jsString(&vm, nameAndMessage), DontEnum);
    4040    putDirect(vm, vm.propertyNames->message, jsEmptyString(&vm), DontEnum);
  • trunk/Source/JavaScriptCore/runtime/NativeErrorPrototype.h

    r173269 r198469  
    11/*
    22 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
    3  *  Copyright (C) 2008 Apple Inc. All rights reserved.
     3 *  Copyright (C) 2008, 2016 Apple Inc. All rights reserved.
    44 *
    55 *  This library is free software; you can redistribute it and/or
     
    3535    typedef ErrorPrototype Base;
    3636
    37     static NativeErrorPrototype* create(VM& vm, JSGlobalObject* globalObject, Structure* structure, const String& name, NativeErrorConstructor* constructor)
     37    static NativeErrorPrototype* create(VM& vm, Structure* structure, const String& name, NativeErrorConstructor* constructor)
    3838    {
    3939        NativeErrorPrototype* prototype = new (NotNull, allocateCell<NativeErrorPrototype>(vm.heap)) NativeErrorPrototype(vm, structure);
    40         prototype->finishCreation(vm, globalObject, name, constructor);
     40        prototype->finishCreation(vm, name, constructor);
    4141        return prototype;
    4242    }
    4343
    4444protected:
    45     void finishCreation(VM&, JSGlobalObject*, const String& nameAndMessage, NativeErrorConstructor*);
     45    void finishCreation(VM&, const String& nameAndMessage, NativeErrorConstructor*);
    4646};
    4747
  • trunk/Source/JavaScriptCore/tests/es6/miscellaneous_built-in_prototypes_are_not_instances.js

    r189333 r198469  
    77  Date.prototype.valueOf(); return false;
    88} catch(e) {}
     9
     10if (![Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError].every(function (E) {
     11    return Object.prototype.toString.call(E.prototype) === '[object Object]';
     12})) {
     13  return false;
     14}
     15
    916return true;
    1017     
Note: See TracChangeset for help on using the changeset viewer.