Skip to content

Commit

Permalink
fixed #180 (calling non existing default constructor)
Browse files Browse the repository at this point in the history
removed asserts for failed registered instances so runtime does not fail
  • Loading branch information
blagoev committed Oct 1, 2015
1 parent 0a77c8a commit cb69661
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 20 deletions.
8 changes: 0 additions & 8 deletions src/jni/MetadataNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,6 @@ void MetadataNode::InnerClassConstructorCallback(const v8::FunctionCallbackInfo<

string fullClassName = CreateFullClassName(className, extendName);
bool success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, outerThis, false);

assert(success);
}

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

bool success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, implementationObject, false);

assert(success);
}


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

auto success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, implementationObject, true);

assert(success);
}

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

string fullClassName = CreateFullClassName(className, extendName);
bool success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, outerThis, false);

//assert(success);
}

void MetadataNode::MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
Expand Down
6 changes: 6 additions & 0 deletions src/src/com/tns/MethodResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,12 @@ else if (assignTo.equals(char.class))
public static boolean convertConstructorArgs(Constructor<?> ctor, Object[] args)
{
boolean success = true;

if (ctor == null)
{
success = false;
return success;
}

Class<?>[] paramTypes;
if (constructorParamTypeCache.containsKey(ctor))
Expand Down
17 changes: 10 additions & 7 deletions src/src/com/tns/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,18 @@ private static Object createInstance(Object[] args, int objectId, int constructo
{
StringBuilder builder = new StringBuilder();
builder.append(constructorId + "(");
for (Object arg : args)
if (args != null)
{
if (arg != null)
for (Object arg : args)
{
builder.append(arg.toString() + ", ");
}
else
{
builder.append("null, ");
if (arg != null)
{
builder.append(arg.toString() + ", ");
}
else
{
builder.append("null, ");
}
}
}
builder.append(")");
Expand Down
1 change: 1 addition & 0 deletions src/src/com/tns/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static boolean runPlugin(Logger logger, Context context)
{
if (logger.isEnabled()) e.printStackTrace();
}

try
{
Class<?> liveSyncPluginClass = Class.forName(pluginClassName);
Expand Down
4 changes: 2 additions & 2 deletions test-app/assets/app/mainpage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__disableVerboseLogging();

__log("starting tests");
require("./tests/testWeakRef");
require("./tests/tests");
require("./tests/testMethodResolution");
Expand All @@ -26,9 +26,9 @@ var MainActivity = {
var k = this.toString();
__log("this.toString " + k);
this.super.onCreate(bundle);
//this.super.onCreate(null);

require("./tests/testsWithContext").run(this);

execute(); //run jasmine

var layout = new android.widget.LinearLayout(this);
Expand Down
7 changes: 4 additions & 3 deletions test-app/assets/app/tests/testIfAbleToRunExternalFile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
describe("Tests running external files", function () {

it("When_file_outside_the_project_folder_is_required_it_should_fail", function () {

__log("When_file_outside_the_project_folder_is_required_it_should_throw_IllegalAccessException");

__log("TEST: When_file_outside_the_project_folder_is_required_it_should_fail");
var illegalAccesExceptionCaught = false;
var fileSeparator = "/";
var nonExistingFileName = "nonExistingFile";
Expand All @@ -26,4 +26,5 @@ describe("Tests running external files", function () {

expect(exceptionCaught).toBe(true);
});

});
23 changes: 23 additions & 0 deletions test-app/assets/app/tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1863,4 +1863,27 @@ describe("Tests ", function () {

expect(value123).toBe(123);
});


it("When_calling_non_existent_ctor_it_should_fail", function () {

__log("TEST: When_calling_non_existent_ctor_it_should_fail: Start");

try
{
var textView = android.widget.TextView;
var MyTextView = textView.extend({

});

var my = new MyTextView();
}
catch(e)
{
exceptionCaught = true;
}

expect(exceptionCaught).toBe(true);
});

});

0 comments on commit cb69661

Please sign in to comment.