Skip to content

Commit

Permalink
replace ASSERT_MESSAGE with V8 exception (issue #221)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail Slavchev committed Nov 6, 2015
1 parent ab34c05 commit 04293aa
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/jni/NativeScriptRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,23 @@ void NativeScriptRuntime::RequireCallback(const v8::FunctionCallbackInfo<v8::Val
{
SET_PROFILER_FRAME();

ASSERT_MESSAGE(args.Length() == 2, "require should be called with two parameters");
ASSERT_MESSAGE(!args[0]->IsUndefined() && !args[0]->IsNull(), "require called with undefined moduleName parameter");
ASSERT_MESSAGE(!args[1]->IsUndefined() && !args[1]->IsNull(), "require called with undefined callingModulePath parameter");
ASSERT_MESSAGE(args[0]->IsString(), "require should be called with string parameter");
ASSERT_MESSAGE(args[1]->IsString(), "require should be called with string parameter");
auto isolate = Isolate::GetCurrent();

if (args.Length() != 2)
{
isolate->ThrowException(ConvertToV8String("require should be called with two parameters"));
return;
}
if (!args[0]->IsString())
{
isolate->ThrowException(ConvertToV8String("require's first parameter should be string"));
return;
}
if (!args[1]->IsString())
{
isolate->ThrowException(ConvertToV8String("require's second parameter should be string"));
return;
}

string moduleName = ConvertToString(args[0].As<String>());
string callingModuleDirName = ConvertToString(args[1].As<String>());
Expand All @@ -861,8 +873,6 @@ void NativeScriptRuntime::RequireCallback(const v8::FunctionCallbackInfo<v8::Val
JniLocalRef jsCallingModuleDirName(env.NewStringUTF(callingModuleDirName.c_str()));
JniLocalRef jsModulePath(env.CallStaticObjectMethod(RequireClass, GET_MODULE_PATH_METHOD_ID, (jstring) jsModulename, (jstring) jsCallingModuleDirName));

auto isolate = Isolate::GetCurrent();

// cache the required modules by full path, not name only, since there might be some collisions with relative paths and names
string modulePath = ArgConverter::jstringToString((jstring) jsModulePath);
if(modulePath == ""){
Expand Down

0 comments on commit 04293aa

Please sign in to comment.