Skip to content

Commit 0978df8

Browse files
author
Mihail Slavchev
committed
add a check for 'extend' to fail when called as constructor
1 parent f85e445 commit 0978df8

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

src/jni/MetadataNode.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,13 @@ MetadataNode::ExtendedClassCacheData MetadataNode::GetCachedExtendedClassData(Is
10511051

10521052
void MetadataNode::ExtendCallMethodHandler(const v8::FunctionCallbackInfo<v8::Value>& info)
10531053
{
1054+
if (info.IsConstructCall())
1055+
{
1056+
string exMsg("Cannot call 'extend' as constructor");
1057+
ExceptionUtil::GetInstance()->ThrowExceptionToJs(exMsg);
1058+
return;
1059+
}
1060+
10541061
SET_PROFILER_FRAME();
10551062

10561063
Handle<Object> implementationObject;

test-app/assets/app/tests/extendedClassesTests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe("Tests extended classes ", function () {
22

33
it("Instance_with_no_extension_shouldnt_use_previously_defined_implementation_object", function () {
4-
var MyButton = new com.tns.tests.Button1.extend({
4+
var MyButton = com.tns.tests.Button1.extend({
55
toString: function () {
66
return "overriden toString method of chronometer instance";
77
},
@@ -24,7 +24,7 @@ describe("Tests extended classes ", function () {
2424

2525
it("Instance_with_extension_shouldnt_use_previously_defined_implementation_object", function () {
2626

27-
var MyButton = new com.tns.tests.Button1.extend({
27+
var MyButton = com.tns.tests.Button1.extend({
2828
toString: function () {
2929
return "overriden toString method of button instance";
3030
},
@@ -37,7 +37,7 @@ describe("Tests extended classes ", function () {
3737
var labelgetIMAGE_ID_PROP = button.getIMAGE_ID_PROP();
3838
//
3939

40-
var MyButton1 = new com.tns.tests.Button1.extend({
40+
var MyButton1 = com.tns.tests.Button1.extend({
4141
toString: function () {
4242
return "overriden toString method of button1 instance ";
4343
},
@@ -59,7 +59,7 @@ describe("Tests extended classes ", function () {
5959
var labelgetIMAGE_ID_PROP1 = button1.getIMAGE_ID_PROP();
6060

6161
//
62-
var MyButton = new com.tns.tests.Button1.extend({
62+
var MyButton = com.tns.tests.Button1.extend({
6363
getIMAGE_ID_PROP: function () {
6464
return "overriden getIMAGE_ID_PROP method on button";
6565
}

test-app/assets/app/tests/tests.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe("Tests ", function () {
4040
button1.setLabel("first button");
4141

4242
__log("TEST: Creating MyButton2 class");
43-
var MyButton2 = new com.tns.tests.Button1.extend("MyButton", {
43+
var MyButton2 = com.tns.tests.Button1.extend("MyButton", {
4444
toString : function() {
4545
return "button2";
4646
}});
@@ -79,7 +79,7 @@ describe("Tests ", function () {
7979
button1.setLabel("first button");
8080

8181
__log("TEST: Creating MyButton2 class");
82-
var MyButton2 = new com.tns.tests.Button1.extend({
82+
var MyButton2 = com.tns.tests.Button1.extend({
8383
toString : function() {
8484
return "button2";
8585
}});
@@ -136,7 +136,7 @@ describe("Tests ", function () {
136136

137137
__log("TEST: When_implementing_an_interface_with_new__the_overrides_should_work");
138138

139-
var MyButton = new com.tns.tests.Button1.extend("MyButton60", {
139+
var MyButton = com.tns.tests.Button1.extend("MyButton60", {
140140
toString : function() {
141141
return "button1";
142142
}
@@ -158,7 +158,7 @@ describe("Tests ", function () {
158158

159159
__log("TEST: When_calling_instanceof_on_field_result_it_should_work");
160160

161-
var MyButton = new com.tns.tests.Button1.extend("MyButton81", {
161+
var MyButton = com.tns.tests.Button1.extend("MyButton81", {
162162
toString : function() {
163163
return "button1";
164164
},
@@ -176,7 +176,7 @@ describe("Tests ", function () {
176176

177177
__log("TEST: When_calling_instanceof_on_method_result_it_should_work");
178178

179-
var MyButton = new com.tns.tests.Button1.extend("MyButton98", {
179+
var MyButton = com.tns.tests.Button1.extend("MyButton98", {
180180
toString : function() {
181181
return "button1";
182182
},
@@ -196,7 +196,7 @@ describe("Tests ", function () {
196196

197197
var isInstanceOf;
198198

199-
var MyButton = new com.tns.tests.Button1.extend("MyButton115", {
199+
var MyButton = com.tns.tests.Button1.extend("MyButton115", {
200200
toString : function() {
201201
return "button1";
202202
},
@@ -453,7 +453,7 @@ describe("Tests ", function () {
453453

454454
__log("TEST: When_implementing_an_interface_with_new__the_overrides_should_work");
455455

456-
var MyButton = new com.tns.tests.Button1.extend({
456+
var MyButton = com.tns.tests.Button1.extend({
457457
toString : function() {
458458
return "button1";
459459
}
@@ -477,7 +477,7 @@ describe("Tests ", function () {
477477

478478
__log("TEST: When_a_java_method_returns_object_that_needs_js_instance__it_should_create_the_instance");
479479

480-
var MyButton = new com.tns.tests.Button1.extend("MyButton381", {
480+
var MyButton = com.tns.tests.Button1.extend("MyButton381", {
481481
toString : function() {
482482
return "button1";
483483
}
@@ -501,7 +501,7 @@ describe("Tests ", function () {
501501

502502
__log("TEST: When_a_java_method_returns_object_that_needs_js_instance__it_should_create_the_instance_according_to_the_actual_return_type");
503503

504-
var Button = new com.tns.tests.Button1.extend("MyButton397", {
504+
var Button = com.tns.tests.Button1.extend("MyButton397", {
505505
toString : function() {
506506
return "button1";
507507
}
@@ -518,7 +518,7 @@ describe("Tests ", function () {
518518

519519
__log("TEST: When_a_java_field_returns_object_that_needs_js_instance__it_should_create_the_instance_according_to_the_actual_return_type");
520520

521-
var Button = new com.tns.tests.Button1.extend("MyButton413", {
521+
var Button = com.tns.tests.Button1.extend("MyButton413", {
522522
toString : function() {
523523
return "button1";
524524
}
@@ -536,7 +536,7 @@ describe("Tests ", function () {
536536
__log("TEST: When_a_java_argument_is_passed_to_js_that_needs_js_instance__it_should_create_the_instance_according_to_the_actual_return_type");
537537

538538
var name = "";
539-
var Button = new com.tns.tests.Button1.extend("MyButton418", {
539+
var Button = com.tns.tests.Button1.extend("MyButton418", {
540540
toString : function() {
541541
return "button1";
542542
},
@@ -557,7 +557,7 @@ describe("Tests ", function () {
557557

558558
__log("TEST: When_a_java_object_is_returned_from_indexer_that_needs_js_instance__it_should_create_the_instance_according_to_the_actual_return_type");
559559

560-
var Button = new com.tns.tests.Button1.extend("MyButton450", {
560+
var Button = com.tns.tests.Button1.extend("MyButton450", {
561561
toString : function() {
562562
return "button1";
563563
}
@@ -686,7 +686,7 @@ describe("Tests ", function () {
686686
var ctorCalled = false;
687687
var isConstructor = false;
688688

689-
var MyButton = new com.tns.tests.Button1.extend("MyButton574", {
689+
var MyButton = com.tns.tests.Button1.extend("MyButton574", {
690690
init : function() {
691691
ctorCalled = true;
692692
isConstructor = arguments[arguments.length - 1];
@@ -1568,7 +1568,7 @@ describe("Tests ", function () {
15681568

15691569
var exceptionCaught = false;
15701570

1571-
var Button1 = new com.tns.tests.Button1.extend("Button1", implObj);
1571+
var Button1 = com.tns.tests.Button1.extend("Button1", implObj);
15721572

15731573
try
15741574
{

test-app/assets/app/tests/testsForRuntimeBindingGenerator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("Tests for runtime binding generator", function () {
1212

1313
__log("TEST: When_generating_a_proxy_of_nested_interface_at_runtime");
1414

15-
var MyButton = new com.tns.tests.Button1.extend("MyButton10", {
15+
var MyButton = com.tns.tests.Button1.extend("MyButton10", {
1616
toString : function() {
1717
return "button1";
1818
},
@@ -36,7 +36,7 @@ describe("Tests for runtime binding generator", function () {
3636

3737
__log("TEST: When_generating_a_proxy_of_android_class_at_runtime");
3838

39-
var MyButton = new com.tns.tests.Button1.extend("MyButton36", {
39+
var MyButton = com.tns.tests.Button1.extend("MyButton36", {
4040
toString : function() {
4141
return "button1";
4242
},

test-app/assets/app/tests/testsWithContext.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ exports.run = function(cntxt)
1818
var ctorCalled = false;
1919
var isConstructor = false;
2020

21-
var MyButton = new android.widget.Button.extend({
21+
var MyButton = android.widget.Button.extend({
2222
init : function() {
2323
ctorCalled = true;
2424
isConstructor = arguments[arguments.length - 1];

0 commit comments

Comments
 (0)