Add argcount checking to functions and ctors.
Before argument counts were only checked for overloaded functions/ctors. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/oliverb-javascript-v8@13791 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d5c5f7ebee
commit
9b0c8dae83
2 changed files with 35 additions and 16 deletions
|
|
@ -52,6 +52,8 @@ JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef th
|
||||||
{
|
{
|
||||||
$jslocals
|
$jslocals
|
||||||
JSValueRef jsresult;
|
JSValueRef jsresult;
|
||||||
|
|
||||||
|
if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||||
|
|
||||||
$jscode
|
$jscode
|
||||||
return jsresult;
|
return jsresult;
|
||||||
|
|
@ -68,6 +70,8 @@ int $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObjec
|
||||||
{
|
{
|
||||||
$jslocals
|
$jslocals
|
||||||
JSValueRef jsresult;
|
JSValueRef jsresult;
|
||||||
|
|
||||||
|
if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||||
|
|
||||||
$jscode
|
$jscode
|
||||||
*result = jsresult;
|
*result = jsresult;
|
||||||
|
|
@ -231,6 +235,9 @@ ctor_dispatch_case: This template is used for the constructor which is overloade
|
||||||
JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||||
{
|
{
|
||||||
$jslocals
|
$jslocals
|
||||||
|
|
||||||
|
if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||||
|
|
||||||
$jscode
|
$jscode
|
||||||
|
|
||||||
return SWIG_JSC_NewPointerObj(context, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
|
return SWIG_JSC_NewPointerObj(context, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
|
||||||
|
|
@ -240,6 +247,7 @@ JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
initializer:This template is dynamic growing and aggregates everything
|
initializer:This template is dynamic growing and aggregates everything
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
|
||||||
|
|
@ -934,16 +934,20 @@ void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Ma
|
||||||
String *tm;
|
String *tm;
|
||||||
Parm *p;
|
Parm *p;
|
||||||
|
|
||||||
int num_args = emit_num_arguments(parms);
|
// determine an offset index, as members have an extra 'this' argument
|
||||||
|
// except: static members and ctors.
|
||||||
|
int startIdx = 0;
|
||||||
|
if (is_member && !is_static && mode!=Ctor) {
|
||||||
|
startIdx = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// store number of arguments for argument checks
|
||||||
|
int num_args = emit_num_arguments(parms) - startIdx;
|
||||||
String *argcount = NewString("");
|
String *argcount = NewString("");
|
||||||
Printf(argcount, "%d", num_args);
|
Printf(argcount, "%d", num_args);
|
||||||
Setattr(n, ARGCOUNT, argcount);
|
Setattr(n, ARGCOUNT, argcount);
|
||||||
|
|
||||||
int startIdx = 0;
|
// process arguments
|
||||||
if (is_member && !is_static) {
|
|
||||||
startIdx = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (p = parms; p; p = nextSibling(p), i++) {
|
for (p = parms; p; p = nextSibling(p), i++) {
|
||||||
SwigType *pt = Getattr(p, "type");
|
SwigType *pt = Getattr(p, "type");
|
||||||
|
|
@ -957,7 +961,6 @@ void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Ma
|
||||||
} else {
|
} else {
|
||||||
Printf(arg, "argv[%d]", i - startIdx);
|
Printf(arg, "argv[%d]", i - startIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Setter:
|
case Setter:
|
||||||
if (is_member && !is_static && i == 0) {
|
if (is_member && !is_static && i == 0) {
|
||||||
|
|
@ -1213,12 +1216,16 @@ int JSCEmitter::exitClass(Node *n) {
|
||||||
int JSEmitter::emitCtor(Node *n) {
|
int JSEmitter::emitCtor(Node *n) {
|
||||||
|
|
||||||
Wrapper *wrapper = NewWrapper();
|
Wrapper *wrapper = NewWrapper();
|
||||||
|
|
||||||
|
bool is_overloaded = GetFlag(n, "sym:overloaded");
|
||||||
|
|
||||||
Template t_ctor(getTemplate("JS_ctordefn"));
|
Template t_ctor(getTemplate("JS_ctordefn"));
|
||||||
|
|
||||||
//String *mangled_name = SwigType_manglestr(Getattr(n, "name"));
|
//String *mangled_name = SwigType_manglestr(Getattr(n, "name"));
|
||||||
String *wrap_name = Swig_name_wrapper(Getattr(n, "sym:name"));
|
String *wrap_name = Swig_name_wrapper(Getattr(n, "sym:name"));
|
||||||
Append(wrap_name, Getattr(n, "sym:overname"));
|
if(is_overloaded) {
|
||||||
|
Append(wrap_name, Getattr(n, "sym:overname"));
|
||||||
|
}
|
||||||
Setattr(n, "wrap:name", wrap_name);
|
Setattr(n, "wrap:name", wrap_name);
|
||||||
// note: removing the is_abstract flag, as this emitter
|
// note: removing the is_abstract flag, as this emitter
|
||||||
// is supposed to be called for non-abstract classes only.
|
// is supposed to be called for non-abstract classes only.
|
||||||
|
|
@ -1238,6 +1245,7 @@ int JSEmitter::emitCtor(Node *n) {
|
||||||
.replace(T_TYPE_MANGLED, state.clazz(TYPE_MANGLED))
|
.replace(T_TYPE_MANGLED, state.clazz(TYPE_MANGLED))
|
||||||
.replace(T_LOCALS, wrapper->locals)
|
.replace(T_LOCALS, wrapper->locals)
|
||||||
.replace(T_CODE, wrapper->code)
|
.replace(T_CODE, wrapper->code)
|
||||||
|
.replace(T_ARGCOUNT, Getattr(n, ARGCOUNT))
|
||||||
.pretty_print(f_wrappers);
|
.pretty_print(f_wrappers);
|
||||||
|
|
||||||
Template t_ctor_case(getTemplate("JS_ctor_dispatch_case"));
|
Template t_ctor_case(getTemplate("JS_ctor_dispatch_case"));
|
||||||
|
|
@ -1247,14 +1255,16 @@ int JSEmitter::emitCtor(Node *n) {
|
||||||
|
|
||||||
DelWrapper(wrapper);
|
DelWrapper(wrapper);
|
||||||
|
|
||||||
// create a dispatching ctor (if necessary)
|
// create a dispatching ctor
|
||||||
if (!Getattr(n, "sym:nextSibling")) {
|
if(is_overloaded) {
|
||||||
String *wrap_name = Swig_name_wrapper(Getattr(n, "sym:name"));
|
if (!Getattr(n, "sym:nextSibling")) {
|
||||||
Template t_mainctor(getTemplate("JS_mainctordefn"));
|
String *wrap_name = Swig_name_wrapper(Getattr(n, "sym:name"));
|
||||||
t_mainctor.replace(T_WRAPPER, wrap_name)
|
Template t_mainctor(getTemplate("JS_mainctordefn"));
|
||||||
.replace(T_DISPATCH_CASES, state.clazz(CTOR_DISPATCHERS))
|
t_mainctor.replace(T_WRAPPER, wrap_name)
|
||||||
.pretty_print(f_wrappers);
|
.replace(T_DISPATCH_CASES, state.clazz(CTOR_DISPATCHERS))
|
||||||
state.clazz(CTOR, wrap_name);
|
.pretty_print(f_wrappers);
|
||||||
|
state.clazz(CTOR, wrap_name);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
state.clazz(CTOR, wrap_name);
|
state.clazz(CTOR, wrap_name);
|
||||||
}
|
}
|
||||||
|
|
@ -1410,6 +1420,7 @@ int JSEmitter::emitFunction(Node *n, bool is_member, bool is_static) {
|
||||||
t_function.replace(T_WRAPPER, wrap_name)
|
t_function.replace(T_WRAPPER, wrap_name)
|
||||||
.replace(T_LOCALS, wrapper->locals)
|
.replace(T_LOCALS, wrapper->locals)
|
||||||
.replace(T_CODE, wrapper->code)
|
.replace(T_CODE, wrapper->code)
|
||||||
|
.replace(T_ARGCOUNT, Getattr(n, ARGCOUNT))
|
||||||
.pretty_print(f_wrappers);
|
.pretty_print(f_wrappers);
|
||||||
|
|
||||||
// handle function overloading
|
// handle function overloading
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue