Open mattconnolly opened 11 years ago
I'm not sure why this started happening, or if it was always a problem. It looks like execjs's #call uses apply and changes the context the function expects to have, resulting in the error. Here are some workarounds:
You can add a wrapping function around the parse fn, to protect the context of 'this' in the parse fn:
$libphonenumber.context.call "(function (a,b) { return i18n.phonenumbers.PhoneNumberUtil.getInstance().parse(a,b); })", "+19255550100", "US"
Or you can use eval directly:
$libphonenumber.context.eval "(function () { inst = i18n.phonenumbers.PhoneNumberUtil.getInstance(); return inst.parse('9255550100', 'US'); })()"
$libphonenumber.context.eval "(function () { inst = i18n.phonenumbers.PhoneNumberUtil.getInstance(); phone_obj = inst.parse('9255550100', 'US'); return inst.isValidNumber(phone_obj); })()"
Unfortunately I don't have time right now to dive too deep into this and make sure these are the correct solutions, but I'll try and patch this up in the library soon.
I'm getting the following error when using libphonenumber-execjs (0.0.2) from ruby 1.9.3 (from irb):
Is ruby 1.9.3 supported? Or is this a Javascript problem?