Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/NativeScript/ObjC/Inheritance/ObjCTypeScriptExtend.mm
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ EncodedJSValue ObjCTypeScriptExtendFunction(ExecState* execState) {

JSScope* scope = callFrame->scope(callFrame->codeBlock()->scopeRegister().offset());
Identifier constructorName = Identifier::fromString(execState, name);
JSValue value = JSScope::resolve(execState, scope, constructorName);
if (value.isObject()) {
PutPropertySlot slot(value);
value.put(execState, constructorName, derivedConstructor, slot);
JSValue containingScope = JSScope::resolve(execState, scope, constructorName);
if (containingScope.isObject()) {
JSValue currentValue = containingScope.get(execState, constructorName);
if (currentValue.isCell() && currentValue.asCell() == typeScriptConstructor) {
PutPropertySlot slot(containingScope);
containingScope.put(execState, constructorName, derivedConstructor, slot);
}
}

// imp_implementationWithBlock calls block copy, class copy and initialize gets skipped
Expand Down
43 changes: 25 additions & 18 deletions tests/TestRunner/app/Inheritance/TypeScriptTests.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// TODO: Use TypeScript definitions when they get ready
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var TSObject = (function (_super) {
__extends(TSObject, _super);
function TSObject() {
Expand Down Expand Up @@ -108,18 +102,6 @@ var TSObject1 = (function (_super) {
TSObject1.ObjCProtocols = [TNSBaseProtocol2];
return TSObject1;
})(NSObject);
var A = (function () {
function A() {
}
return A;
})();
var B = (function (_super) {
__extends(B, _super);
function B() {
_super.apply(this, arguments);
}
return B;
})(A);
var UnusedConstructor = (function (_super) {
__extends(UnusedConstructor, _super);
function UnusedConstructor() {
Expand Down Expand Up @@ -213,6 +195,31 @@ describe(module.id, function () {
'baseProtocolProperty1Optional called');
});
it('PlainExtends', function () {
var A = (function () {
function A() {
}
return A;
})();
var B = (function (_super) {
__extends(B, _super);
function B() {
_super.apply(this, arguments);
}
return B;
})(A);
expect(new B() instanceof A).toBe(true);
});
it('Scope', function () {
global["Derived"] = 3;
var Derived = (function (_super) {
__extends(Derived, _super);
function Derived() {
_super.apply(this, arguments);
}
return Derived;
})(NSObject);
;
expect(global["Derived"]).toBe(3);
delete global["Derived"];
});
});
19 changes: 13 additions & 6 deletions tests/TestRunner/app/Inheritance/TypeScriptTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@ class TSObject1 extends NSObject {
public static ObjCProtocols = [TNSBaseProtocol2];
}

class A {
}

class B extends A {
}

class UnusedConstructor extends NSObject {
private x = 3;
}
Expand Down Expand Up @@ -286,6 +280,19 @@ describe(module.id, function () {
});

it('PlainExtends', function () {
class A {
}

class B extends A {
}

expect(new B() instanceof A).toBe(true);
});

it('Scope', function () {
global["Derived"] = 3;
class Derived extends NSObject { };
expect(global["Derived"]).toBe(3);
delete global["Derived"];
});
});