weimingtom / minijoe

Automatically exported from code.google.com/p/minijoe
1 stars 0 forks source link

String.split doesn't work #15

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
String.split doesn't work. In JsObject, the STRING_PROTOTYPE does not
define the method name and parameter count.

In the actual implementation in evalNative, there's also a bug if the
caller doesn't not specify the "limit." In that case, an empty JsArray is
returned and instead it should split the whole string.

Original issue reported on code.google.com by tbishop...@gmail.com on 29 Jul 2009 at 8:37

GoogleCodeExporter commented 8 years ago
This should fix it:

JsObject.cs

public static final JsObject STRING_PROTOTYPE = 
....
.addVar("slice", new JsFunction(ID_SLICE, 2))
.addVar("split", new JsFunction(ID_SPLIT, 2))
.addVar("substring", new JsFunction(ID_SUBSTRING, 2))
...

evalNative(int index, JsArray stack, int sp, int parCount)
{
  ...
  case ID_SPLIT:
  {
    ...
    double limit = stack.isNull(sp + 3) ? Double.NaN : stack.getNumber(sp + 3);
    ...

Original comment by dak...@gmail.com on 12 Oct 2009 at 1:21