diff options
author | Olly Betts <olly@survex.com> | 2023-04-27 07:43:28 +1200 |
---|---|---|
committer | Olly Betts <olly@survex.com> | 2023-04-27 07:45:10 +1200 |
commit | ca748cfe571fefad218b885894853ca1ade09377 (patch) | |
tree | b868d0244df06743c7c1b4ee6e24765004f7b6ac | |
parent | d9aeb0130662bc8c4f391ed35096ddf3c78b256d (diff) | |
parent | df2ef48ed770305dfeac5bf59df2802930b45d17 (diff) | |
download | swig-ca748cfe571fefad218b885894853ca1ade09377.tar.gz |
Merge branch 'js-numinputs'
-rw-r--r-- | CHANGES.current | 3 | ||||
-rw-r--r-- | Examples/test-suite/javascript/ignore_parameter_runme.js | 24 | ||||
-rw-r--r-- | Source/Modules/javascript.cxx | 31 |
3 files changed, 42 insertions, 16 deletions
diff --git a/CHANGES.current b/CHANGES.current index 95a8619a7..1b5b8dfef 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.2.0 (in progress) =========================== +2023-04-26: mmomtchev + [Javascript] Take into account numinputs when counting arguments. + 2023-04-24: olly [PHP] Add throws typemaps for std:string* and const std::string*. diff --git a/Examples/test-suite/javascript/ignore_parameter_runme.js b/Examples/test-suite/javascript/ignore_parameter_runme.js new file mode 100644 index 000000000..07dcf2f7d --- /dev/null +++ b/Examples/test-suite/javascript/ignore_parameter_runme.js @@ -0,0 +1,24 @@ +const ignore_parameter = require('ignore_parameter'); + +function check(a, b) { + if (a !== b) throw new Error(`'${a}' != '${b}`); +} + +check(ignore_parameter.jaguar(200, 0), "hello"); +check(ignore_parameter.lotus("foo", 1), 101); +check(ignore_parameter.tvr("bar", 2), 8.8); +check(ignore_parameter.ferrari(), 101); +check(ignore_parameter.fiat(17), 17); + +car = new ignore_parameter.SportsCars(); +check(car.daimler(200, 0), "hello"); +check(car.astonmartin("foo", 1), 101); +check(car.bugatti("bar", 2), 8.8); +check(car.lamborghini(), 101); +check(car.maseratti(289), 289); +check(car.audi(), 8.8); + +new ignore_parameter.MiniCooper(200, 0); +new ignore_parameter.MorrisMinor("baz", 0); +new ignore_parameter.FordAnglia("quux", 200); +new ignore_parameter.AustinAllegro(); diff --git a/Source/Modules/javascript.cxx b/Source/Modules/javascript.cxx index 2fbc5505c..fbc7ab455 100644 --- a/Source/Modules/javascript.cxx +++ b/Source/Modules/javascript.cxx @@ -264,8 +264,6 @@ protected: */ Node *getBaseClass(Node *n); - Parm *skipIgnoredArgs(Parm *p); - virtual int createNamespace(String *scope); virtual Hash *createNamespaceEntry(const char *name, const char *parent, const char *parent_mangled); @@ -689,17 +687,6 @@ int JSEmitter::initialize(Node * /*n */ ) { return SWIG_OK; } -/* --------------------------------------------------------------------- - * skipIgnoredArgs() - * --------------------------------------------------------------------- */ - -Parm *JSEmitter::skipIgnoredArgs(Parm *p) { - while (checkAttribute(p, "tmap:in:numinputs", "0")) { - p = Getattr(p, "tmap:in:next"); - } - return p; -} - /* ----------------------------------------------------------------------------- * JSEmitter::getBaseClass() : the node of the base class or NULL * @@ -1537,7 +1524,7 @@ void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Ma // process arguments int i = 0; - for (p = parms; p; i++) { + for (p = parms; p;) { String *arg = NewString(""); String *type = Getattr(p, "type"); @@ -1550,19 +1537,24 @@ void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Ma case Function: if (is_member && !is_static && i == 0) { Printv(arg, "thisObject", 0); + i++; } else { Printf(arg, "argv[%d]", i - startIdx); + i += GetInt(p, "tmap:in:numinputs"); } break; case Setter: if (is_member && !is_static && i == 0) { Printv(arg, "thisObject", 0); + i++; } else { Printv(arg, "value", 0); + i++; } break; case Ctor: Printf(arg, "argv[%d]", i); + i += GetInt(p, "tmap:in:numinputs"); break; default: Printf(stderr, "Illegal MarshallingMode."); @@ -2173,7 +2165,7 @@ void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Mar Setattr(n, ARGCOUNT, argcount); int i = 0; - for (p = parms; p; i++) { + for (p = parms; p;) { String *arg = NewString(""); String *type = Getattr(p, "type"); @@ -2185,26 +2177,33 @@ void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Mar case Getter: if (is_member && !is_static && i == 0) { Printv(arg, "info.Holder()", 0); + i++; } else { - Printf(arg, "args[%d]", i - startIdx); + Printf(arg, "args[%d]", i - startIdx); + i += GetInt(p, "tmap:in:numinputs"); } break; case Function: if (is_member && !is_static && i == 0) { Printv(arg, "args.Holder()", 0); + i++; } else { Printf(arg, "args[%d]", i - startIdx); + i += GetInt(p, "tmap:in:numinputs"); } break; case Setter: if (is_member && !is_static && i == 0) { Printv(arg, "info.Holder()", 0); + i++; } else { Printv(arg, "value", 0); + i++; } break; case Ctor: Printf(arg, "args[%d]", i); + i += GetInt(p, "tmap:in:numinputs"); break; default: Printf(stderr, "Illegal MarshallingMode."); |