Changeset 202846 in webkit
- Timestamp:
- Jul 5, 2016 10:04:05 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r202845 r202846 1 2016-07-05 Joseph Pecoraro <pecoraro@apple.com> 2 3 RELEASE_ASSERT(!thisObject) in ObjCCallbackFunctionImpl::call when calling JSExport ObjC Constructor without operator new 4 https://bugs.webkit.org/show_bug.cgi?id=159446 5 6 Reviewed by Mark Lam. 7 8 * js/class-syntax-call-expected.txt: 9 * js/class-syntax-default-constructor-expected.txt: 10 * js/script-tests/class-syntax-call.js: 11 * js/script-tests/class-syntax-default-constructor.js: 12 Improve error message when calling a class constructor without 'new'. 13 1 14 2016-07-05 David Kilzer <ddkilzer@apple.com> 2 15 -
trunk/LayoutTests/js/class-syntax-call-expected.txt
r190847 r202846 5 5 6 6 PASS new A 7 PASS A():::"TypeError: Cannot call a class constructor "7 PASS A():::"TypeError: Cannot call a class constructor without |new|" 8 8 PASS new B 9 PASS B():::"TypeError: Cannot call a class constructor "9 PASS B():::"TypeError: Cannot call a class constructor without |new|" 10 10 PASS new (class { constructor() {} })() 11 PASS (class { constructor() {} })():::"TypeError: Cannot call a class constructor "11 PASS (class { constructor() {} })():::"TypeError: Cannot call a class constructor without |new|" 12 12 PASS new (class extends null { constructor() { super() } })():::"TypeError: function is not a constructor (evaluating 'super()')" 13 PASS (class extends null { constructor() { super() } })():::"TypeError: Cannot call a class constructor "13 PASS (class extends null { constructor() { super() } })():::"TypeError: Cannot call a class constructor without |new|" 14 14 PASS successfullyParsed is true 15 15 -
trunk/LayoutTests/js/class-syntax-default-constructor-expected.txt
r187680 r202846 5 5 6 6 PASS new A instanceof A 7 PASS A():::TypeError: Cannot call a class constructor 7 PASS A():::TypeError: Cannot call a class constructor without |new| 8 8 PASS A.prototype.constructor instanceof Function 9 9 PASS A.prototype.constructor.name:::"A" 10 10 PASS new B instanceof A; new B instanceof A 11 PASS B():::TypeError: Cannot call a class constructor 11 PASS B():::TypeError: Cannot call a class constructor without |new| 12 12 PASS B.prototype.constructor.name:::"B" 13 13 PASS A !== B -
trunk/LayoutTests/js/script-tests/class-syntax-call.js
r190847 r202846 33 33 34 34 shouldNotThrow('new A'); 35 shouldThrow('A()', '"TypeError: Cannot call a class constructor "');35 shouldThrow('A()', '"TypeError: Cannot call a class constructor without |new|"'); 36 36 shouldNotThrow('new B'); 37 shouldThrow('B()', '"TypeError: Cannot call a class constructor "');37 shouldThrow('B()', '"TypeError: Cannot call a class constructor without |new|"'); 38 38 shouldNotThrow('new (class { constructor() {} })()'); 39 shouldThrow('(class { constructor() {} })()', '"TypeError: Cannot call a class constructor "');39 shouldThrow('(class { constructor() {} })()', '"TypeError: Cannot call a class constructor without |new|"'); 40 40 shouldThrow('new (class extends null { constructor() { super() } })()', '"TypeError: function is not a constructor (evaluating \'super()\')"'); 41 shouldThrow('(class extends null { constructor() { super() } })()', '"TypeError: Cannot call a class constructor "');41 shouldThrow('(class extends null { constructor() { super() } })()', '"TypeError: Cannot call a class constructor without |new|"'); 42 42 43 43 var successfullyParsed = true; -
trunk/LayoutTests/js/script-tests/class-syntax-default-constructor.js
r187680 r202846 44 44 45 45 shouldBeTrue('new A instanceof A'); 46 shouldThrow('A()', '"TypeError: Cannot call a class constructor "');46 shouldThrow('A()', '"TypeError: Cannot call a class constructor without |new|"'); 47 47 shouldBeTrue('A.prototype.constructor instanceof Function'); 48 48 shouldBe('A.prototype.constructor.name', '"A"'); 49 49 shouldBeTrue('new B instanceof A; new B instanceof A'); 50 shouldThrow('B()', '"TypeError: Cannot call a class constructor "');50 shouldThrow('B()', '"TypeError: Cannot call a class constructor without |new|"'); 51 51 shouldBe('B.prototype.constructor.name', '"B"'); 52 52 shouldBeTrue('A !== B'); -
trunk/Source/JavaScriptCore/API/ObjCCallbackFunction.mm
r200430 r202846 429 429 } 430 430 431 CallbackType type() const { return m_type; } 432 431 433 bool isConstructible() 432 434 { … … 455 457 ObjCCallbackFunctionImpl* impl = callback->impl(); 456 458 JSContext *context = [JSContext contextWithJSGlobalContextRef:toGlobalRef(callback->globalObject()->globalExec())]; 459 460 if (impl->type() == CallbackInitMethod) { 461 JSGlobalContextRef contextRef = [context JSGlobalContextRef]; 462 *exception = toRef(JSC::createTypeError(toJS(contextRef), ASCIILiteral("Cannot call a class constructor without |new|"))); 463 return JSValueMakeUndefined(contextRef); 464 } 457 465 458 466 CallbackData callbackData; -
trunk/Source/JavaScriptCore/API/tests/testapi.mm
r190267 r202846 1335 1335 })()"]; 1336 1336 checkResult(@"shouldn't be able to construct ClassC", ![canConstructClassC toBool]); 1337 1337 1338 JSValue *canConstructClassCPrime = [context evaluateScript:@"(function() { \ 1338 1339 try { \ … … 1344 1345 })()"]; 1345 1346 checkResult(@"shouldn't be able to construct ClassCPrime", ![canConstructClassCPrime toBool]); 1347 } 1348 1349 @autoreleasepool { 1350 JSContext *context = [[JSContext alloc] init]; 1351 context[@"ClassA"] = [ClassA class]; 1352 context.exceptionHandler = ^(JSContext *context, JSValue *exception) { 1353 NSLog(@"%@", [exception toString]); 1354 context.exception = exception; 1355 }; 1356 1357 checkResult(@"ObjC Constructor without 'new' pre", !context.exception); 1358 [context evaluateScript:@"ClassA(42)"]; 1359 checkResult(@"ObjC Constructor without 'new' post", context.exception); 1346 1360 } 1347 1361 -
trunk/Source/JavaScriptCore/ChangeLog
r202844 r202846 1 2016-07-05 Joseph Pecoraro <pecoraro@apple.com> 2 3 RELEASE_ASSERT(!thisObject) in ObjCCallbackFunctionImpl::call when calling JSExport ObjC Constructor without operator new 4 https://bugs.webkit.org/show_bug.cgi?id=159446 5 6 Reviewed by Mark Lam. 7 8 Treat ObjC JSExport init constructors like ES6 Class Constructors 9 and throw a TypeError when called without 'new'. 10 11 * API/ObjCCallbackFunction.mm: 12 (JSC::ObjCCallbackFunctionImpl::type): 13 (JSC::objCCallbackFunctionCallAsFunction): 14 When calling an init method as a function instead of construction 15 throw a TypeError. 16 17 * bytecompiler/BytecodeGenerator.cpp: 18 (JSC::BytecodeGenerator::BytecodeGenerator): 19 Improve error message. 20 21 * API/tests/testapi.mm: 22 (testObjectiveCAPIMain): 23 Test we get an exception when calling an ObjC constructor without 'new'. 24 1 25 2016-07-05 Mark Lam <mark.lam@apple.com> 2 26 -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
r202795 r202846 565 565 emitCreateThis(&m_thisRegister); 566 566 } else if (constructorKind() != ConstructorKind::None) 567 emitThrowTypeError("Cannot call a class constructor ");567 emitThrowTypeError("Cannot call a class constructor without |new|"); 568 568 else { 569 569 bool shouldEmitToThis = false;
Note: See TracChangeset
for help on using the changeset viewer.