Skip to content

Commit cb69661

Browse files
committed
fixed #180 (calling non existing default constructor)
removed asserts for failed registered instances so runtime does not fail
1 parent 0a77c8a commit cb69661

File tree

7 files changed

+46
-20
lines changed

7 files changed

+46
-20
lines changed

src/jni/MetadataNode.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,6 @@ void MetadataNode::InnerClassConstructorCallback(const v8::FunctionCallbackInfo<
510510

511511
string fullClassName = CreateFullClassName(className, extendName);
512512
bool success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, outerThis, false);
513-
514-
assert(success);
515513
}
516514

517515
void MetadataNode::InnerClassAccessorGetterCallback(Local<String> property, const PropertyCallbackInfo<Value>& info)
@@ -717,8 +715,6 @@ void MetadataNode::ExtendedClassConstructorCallback(const v8::FunctionCallbackIn
717715
string fullClassName = extData->fullClassName;
718716

719717
bool success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, implementationObject, false);
720-
721-
assert(success);
722718
}
723719

724720

@@ -775,8 +771,6 @@ void MetadataNode::InterfaceConstructorCallback(const v8::FunctionCallbackInfo<v
775771
ArgsWrapper argWrapper(info, ArgType::Interface, Local<Object>());
776772

777773
auto success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, implementationObject, true);
778-
779-
assert(success);
780774
}
781775

782776
void MetadataNode::ClassConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -796,8 +790,6 @@ void MetadataNode::ClassConstructorCallback(const v8::FunctionCallbackInfo<v8::V
796790

797791
string fullClassName = CreateFullClassName(className, extendName);
798792
bool success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, outerThis, false);
799-
800-
//assert(success);
801793
}
802794

803795
void MetadataNode::MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)

src/src/com/tns/MethodResolver.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,12 @@ else if (assignTo.equals(char.class))
481481
public static boolean convertConstructorArgs(Constructor<?> ctor, Object[] args)
482482
{
483483
boolean success = true;
484+
485+
if (ctor == null)
486+
{
487+
success = false;
488+
return success;
489+
}
484490

485491
Class<?>[] paramTypes;
486492
if (constructorParamTypeCache.containsKey(ctor))

src/src/com/tns/Platform.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,18 @@ private static Object createInstance(Object[] args, int objectId, int constructo
289289
{
290290
StringBuilder builder = new StringBuilder();
291291
builder.append(constructorId + "(");
292-
for (Object arg : args)
292+
if (args != null)
293293
{
294-
if (arg != null)
294+
for (Object arg : args)
295295
{
296-
builder.append(arg.toString() + ", ");
297-
}
298-
else
299-
{
300-
builder.append("null, ");
296+
if (arg != null)
297+
{
298+
builder.append(arg.toString() + ", ");
299+
}
300+
else
301+
{
302+
builder.append("null, ");
303+
}
301304
}
302305
}
303306
builder.append(")");

src/src/com/tns/Util.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static boolean runPlugin(Logger logger, Context context)
5757
{
5858
if (logger.isEnabled()) e.printStackTrace();
5959
}
60+
6061
try
6162
{
6263
Class<?> liveSyncPluginClass = Class.forName(pluginClassName);

test-app/assets/app/mainpage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__disableVerboseLogging();
2-
2+
__log("starting tests");
33
require("./tests/testWeakRef");
44
require("./tests/tests");
55
require("./tests/testMethodResolution");
@@ -26,9 +26,9 @@ var MainActivity = {
2626
var k = this.toString();
2727
__log("this.toString " + k);
2828
this.super.onCreate(bundle);
29-
//this.super.onCreate(null);
3029

3130
require("./tests/testsWithContext").run(this);
31+
3232
execute(); //run jasmine
3333

3434
var layout = new android.widget.LinearLayout(this);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
describe("Tests running external files", function () {
22

33
it("When_file_outside_the_project_folder_is_required_it_should_fail", function () {
4-
5-
__log("When_file_outside_the_project_folder_is_required_it_should_throw_IllegalAccessException");
6-
4+
5+
__log("TEST: When_file_outside_the_project_folder_is_required_it_should_fail");
6+
77
var illegalAccesExceptionCaught = false;
88
var fileSeparator = "/";
99
var nonExistingFileName = "nonExistingFile";
@@ -26,4 +26,5 @@ describe("Tests running external files", function () {
2626

2727
expect(exceptionCaught).toBe(true);
2828
});
29+
2930
});

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,4 +1863,27 @@ describe("Tests ", function () {
18631863

18641864
expect(value123).toBe(123);
18651865
});
1866+
1867+
1868+
it("When_calling_non_existent_ctor_it_should_fail", function () {
1869+
1870+
__log("TEST: When_calling_non_existent_ctor_it_should_fail: Start");
1871+
1872+
try
1873+
{
1874+
var textView = android.widget.TextView;
1875+
var MyTextView = textView.extend({
1876+
1877+
});
1878+
1879+
var my = new MyTextView();
1880+
}
1881+
catch(e)
1882+
{
1883+
exceptionCaught = true;
1884+
}
1885+
1886+
expect(exceptionCaught).toBe(true);
1887+
});
1888+
18661889
});

0 commit comments

Comments
 (0)