Changeset 195070 in webkit
- Timestamp:
- Jan 14, 2016 12:45:48 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r195069 r195070 1 2016-01-14 Keith Miller <keith_miller@apple.com> 2 3 [ES6] Support subclassing Function. 4 https://bugs.webkit.org/show_bug.cgi?id=153081 5 6 Reviewed by Geoffrey Garen. 7 8 Rebasline tests with the new clearer error message. 9 10 * js/class-syntax-extends-expected.txt: 11 * js/script-tests/class-syntax-extends.js: 12 1 13 2016-01-14 Zalan Bujtas <zalan@apple.com> 2 14 -
trunk/LayoutTests/js/class-syntax-extends-expected.txt
r190847 r195070 27 27 PASS x = class extends "abc" { constructor() { } }; x.__proto__:::TypeError: The superclass is not an object. 28 28 PASS baseWithBadPrototype = function () {}; baseWithBadPrototype.prototype = 3; new baseWithBadPrototype 29 PASS x = class extends baseWithBadPrototype { constructor() { } }:::TypeError: The superclass's prototypeis not an object.29 PASS x = class extends baseWithBadPrototype { constructor() { } }:::TypeError: The value of the superclass's prototype property is not an object. 30 30 PASS baseWithBadPrototype.prototype = "abc" 31 PASS x = class extends baseWithBadPrototype { constructor() { } }:::TypeError: The superclass's prototypeis not an object.31 PASS x = class extends baseWithBadPrototype { constructor() { } }:::TypeError: The value of the superclass's prototype property is not an object. 32 32 PASS baseWithBadPrototype.prototype = null; x = class extends baseWithBadPrototype { constructor() { } } 33 33 PASS x = 1; c = class extends ++x { constructor() { } };:::SyntaxError: Unexpected token '++' … … 49 49 PASS x = 1; namespace = {}; namespace.A = class { constructor() { } }; namespace.B = class extends (x++, namespace.A) { constructor() { } }; 50 50 PASS x = 1; namespace = {}; namespace.A = class { constructor() { } }; namespace.B = class extends (namespace.A, x++) { constructor() { } };:::TypeError: The superclass is not an object. 51 PASS namespace = {}; namespace.A = class { constructor() { } }; namespace.B = class extends new namespace.A { constructor() { } }:::TypeError: The superclass's prototypeis not an object.52 PASS namespace = {}; namespace.A = class { constructor() { } }; namespace.B = class extends new namespace.A() { constructor() { } }:::TypeError: The superclass's prototypeis not an object.51 PASS namespace = {}; namespace.A = class { constructor() { } }; namespace.B = class extends new namespace.A { constructor() { } }:::TypeError: The value of the superclass's prototype property is not an object. 52 PASS namespace = {}; namespace.A = class { constructor() { } }; namespace.B = class extends new namespace.A() { constructor() { } }:::TypeError: The value of the superclass's prototype property is not an object. 53 53 PASS x = 1; namespace = {}; namespace.A = class { constructor() { } }; try { namespace.B = class extends (x++, namespace.A) { constructor() { } } } catch (e) { } x:::2 54 54 PASS x = 1; namespace = {}; namespace.A = class { constructor() { } }; try { namespace.B = class extends (namespace.A, x++) { constructor() { } } } catch (e) { } x:::2 -
trunk/LayoutTests/js/script-tests/class-syntax-extends.js
r190847 r195070 82 82 shouldThrow('x = class extends "abc" { constructor() { } }; x.__proto__', '"TypeError: The superclass is not an object."'); 83 83 shouldNotThrow('baseWithBadPrototype = function () {}; baseWithBadPrototype.prototype = 3; new baseWithBadPrototype'); 84 shouldThrow('x = class extends baseWithBadPrototype { constructor() { } }', '"TypeError: The superclass\'s prototypeis not an object."');84 shouldThrow('x = class extends baseWithBadPrototype { constructor() { } }', '"TypeError: The value of the superclass\'s prototype property is not an object."'); 85 85 shouldNotThrow('baseWithBadPrototype.prototype = "abc"'); 86 shouldThrow('x = class extends baseWithBadPrototype { constructor() { } }', '"TypeError: The superclass\'s prototypeis not an object."');86 shouldThrow('x = class extends baseWithBadPrototype { constructor() { } }', '"TypeError: The value of the superclass\'s prototype property is not an object."'); 87 87 shouldNotThrow('baseWithBadPrototype.prototype = null; x = class extends baseWithBadPrototype { constructor() { } }'); 88 88 -
trunk/Source/JavaScriptCore/ChangeLog
r195009 r195070 1 2016-01-14 Keith Miller <keith_miller@apple.com> 2 3 [ES6] Support subclassing Function. 4 https://bugs.webkit.org/show_bug.cgi?id=153081 5 6 Reviewed by Geoffrey Garen. 7 8 This patch enables subclassing the Function object. It also fixes an existing 9 bug that prevented users from subclassing functions that have a function in 10 the superclass's prototype property. 11 12 * bytecompiler/NodesCodegen.cpp: 13 (JSC::ClassExprNode::emitBytecode): 14 * runtime/FunctionConstructor.cpp: 15 (JSC::constructWithFunctionConstructor): 16 (JSC::constructFunction): 17 (JSC::constructFunctionSkippingEvalEnabledCheck): 18 * runtime/FunctionConstructor.h: 19 * runtime/JSFunction.cpp: 20 (JSC::JSFunction::create): 21 * runtime/JSFunction.h: 22 (JSC::JSFunction::createImpl): 23 * runtime/JSFunctionInlines.h: 24 (JSC::JSFunction::createWithInvalidatedReallocationWatchpoint): 25 (JSC::JSFunction::JSFunction): Deleted. 26 * tests/stress/class-subclassing-function.js: Added. 27 1 28 2016-01-13 Carlos Garcia Campos <cgarcia@igalia.com> 2 29 -
trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
r194449 r195070 3229 3229 RefPtr<Label> protoParentIsObjectOrNullLabel = generator.newLabel(); 3230 3230 generator.emitJumpIfTrue(generator.emitUnaryOp(op_is_object_or_null, tempRegister.get(), protoParent.get()), protoParentIsObjectOrNullLabel.get()); 3231 generator.emitThrowTypeError(ASCIILiteral("The superclass's prototype is not an object.")); 3231 generator.emitJumpIfTrue(generator.emitUnaryOp(op_is_function, tempRegister.get(), protoParent.get()), protoParentIsObjectOrNullLabel.get()); 3232 generator.emitThrowTypeError(ASCIILiteral("The value of the superclass's prototype property is not an object.")); 3232 3233 generator.emitLabel(protoParentIsObjectOrNullLabel.get()); 3233 3234 -
trunk/Source/JavaScriptCore/runtime/FunctionConstructor.cpp
r194310 r195070 57 57 { 58 58 ArgList args(exec); 59 return JSValue::encode(constructFunction(exec, asInternalFunction(exec->callee())->globalObject(), args ));59 return JSValue::encode(constructFunction(exec, asInternalFunction(exec->callee())->globalObject(), args, FunctionConstructionMode::Function, exec->newTarget())); 60 60 } 61 61 … … 80 80 81 81 // ECMA 15.3.2 The Function Constructor 82 JSObject* constructFunction(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, const Identifier& functionName, const String& sourceURL, const TextPosition& position, FunctionConstructionMode functionConstructionMode )82 JSObject* constructFunction(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, const Identifier& functionName, const String& sourceURL, const TextPosition& position, FunctionConstructionMode functionConstructionMode, JSValue newTarget) 83 83 { 84 84 if (!globalObject->evalEnabled()) 85 85 return exec->vm().throwException(exec, createEvalError(exec, globalObject->evalDisabledErrorMessage())); 86 return constructFunctionSkippingEvalEnabledCheck(exec, globalObject, args, functionName, sourceURL, position, -1, functionConstructionMode );86 return constructFunctionSkippingEvalEnabledCheck(exec, globalObject, args, functionName, sourceURL, position, -1, functionConstructionMode, newTarget); 87 87 } 88 88 … … 90 90 ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, 91 91 const Identifier& functionName, const String& sourceURL, 92 const TextPosition& position, int overrideLineNumber, FunctionConstructionMode functionConstructionMode )92 const TextPosition& position, int overrideLineNumber, FunctionConstructionMode functionConstructionMode, JSValue newTarget) 93 93 { 94 94 // How we stringify functions is sometimes important for web compatibility. … … 125 125 } 126 126 127 return JSFunction::create(exec->vm(), function, globalObject); 127 128 return JSFunction::create(exec->vm(), function, globalObject, InternalFunction::createSubclassStructure(exec, newTarget, globalObject->functionStructure())); 128 129 } 129 130 130 131 // ECMA 15.3.2 The Function Constructor 131 JSObject* constructFunction(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, FunctionConstructionMode functionConstructionMode )132 JSObject* constructFunction(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, FunctionConstructionMode functionConstructionMode, JSValue newTarget) 132 133 { 133 return constructFunction(exec, globalObject, args, exec->propertyNames().anonymous, String(), TextPosition::minimumPosition(), functionConstructionMode );134 return constructFunction(exec, globalObject, args, exec->propertyNames().anonymous, String(), TextPosition::minimumPosition(), functionConstructionMode, newTarget); 134 135 } 135 136 -
trunk/Source/JavaScriptCore/runtime/FunctionConstructor.h
r192937 r195070 62 62 }; 63 63 64 JSObject* constructFunction(ExecState*, JSGlobalObject*, const ArgList&, const Identifier& functionName, const String& sourceURL, const WTF::TextPosition&, FunctionConstructionMode = FunctionConstructionMode::Function );65 JSObject* constructFunction(ExecState*, JSGlobalObject*, const ArgList&, FunctionConstructionMode = FunctionConstructionMode::Function );64 JSObject* constructFunction(ExecState*, JSGlobalObject*, const ArgList&, const Identifier& functionName, const String& sourceURL, const WTF::TextPosition&, FunctionConstructionMode = FunctionConstructionMode::Function, JSValue newTarget = JSValue()); 65 JSObject* constructFunction(ExecState*, JSGlobalObject*, const ArgList&, FunctionConstructionMode = FunctionConstructionMode::Function, JSValue newTarget = JSValue()); 66 66 67 67 JS_EXPORT_PRIVATE JSObject* constructFunctionSkippingEvalEnabledCheck( 68 68 ExecState*, JSGlobalObject*, const ArgList&, const Identifier&, 69 const String&, const WTF::TextPosition&, int overrideLineNumber = -1, FunctionConstructionMode = FunctionConstructionMode::Function); 69 const String&, const WTF::TextPosition&, int overrideLineNumber = -1, 70 FunctionConstructionMode = FunctionConstructionMode::Function, JSValue newTarget = JSValue()); 70 71 71 72 } // namespace JSC -
trunk/Source/JavaScriptCore/runtime/JSFunction.cpp
r195000 r195070 64 64 JSFunction* JSFunction::create(VM& vm, FunctionExecutable* executable, JSScope* scope) 65 65 { 66 JSFunction* result = createImpl(vm, executable, scope); 66 return create(vm, executable, scope, scope->globalObject()->functionStructure()); 67 } 68 69 JSFunction* JSFunction::create(VM& vm, FunctionExecutable* executable, JSScope* scope, Structure* structure) 70 { 71 JSFunction* result = createImpl(vm, executable, scope, structure); 67 72 executable->singletonFunction()->notifyWrite(vm, result, "Allocating a function"); 68 73 return result; -
trunk/Source/JavaScriptCore/runtime/JSFunction.h
r195000 r195070 74 74 75 75 static JSFunction* create(VM&, FunctionExecutable*, JSScope*); 76 static JSFunction* create(VM&, FunctionExecutable*, JSScope*, Structure*); 76 77 #if ENABLE(WEBASSEMBLY) 77 78 static JSFunction* create(VM&, WebAssemblyExecutable*, JSScope*); … … 152 153 protected: 153 154 JS_EXPORT_PRIVATE JSFunction(VM&, JSGlobalObject*, Structure*); 154 JSFunction(VM&, FunctionExecutable*, JSScope*);155 155 JSFunction(VM&, FunctionExecutable*, JSScope*, Structure*); 156 156 … … 180 180 181 181 private: 182 static JSFunction* createImpl(VM& vm, FunctionExecutable* executable, JSScope* scope )183 { 184 JSFunction* function = new (NotNull, allocateCell<JSFunction>(vm.heap)) JSFunction(vm, executable, scope );182 static JSFunction* createImpl(VM& vm, FunctionExecutable* executable, JSScope* scope, Structure* structure) 183 { 184 JSFunction* function = new (NotNull, allocateCell<JSFunction>(vm.heap)) JSFunction(vm, executable, scope, structure); 185 185 ASSERT(function->structure()->globalObject()); 186 186 function->finishCreation(vm); -
trunk/Source/JavaScriptCore/runtime/JSFunctionInlines.h
r191215 r195070 36 36 { 37 37 ASSERT(executable->singletonFunction()->hasBeenInvalidated()); 38 return createImpl(vm, executable, scope );38 return createImpl(vm, executable, scope, scope->globalObject()->functionStructure()); 39 39 } 40 40 41 inline JSFunction::JSFunction(VM& vm, FunctionExecutable* executable, JSScope* scope)42 : Base(vm, scope, scope->globalObject()->functionStructure())43 , m_executable(vm, this, executable)44 , m_rareData()45 {46 }47 48 41 inline JSFunction::JSFunction(VM& vm, FunctionExecutable* executable, JSScope* scope, Structure* structure) 49 42 : Base(vm, scope, structure)
Note: See TracChangeset
for help on using the changeset viewer.