On Sat, Sep 15, 2018 at 10:38 PM Jakob Kummerow <[email protected]>
wrote:
> To create arbitrary BigInts via the C++ API, use BigInt::NewFromWords.
>
maybe this is a new method; it wasn't available, and would require
preparsing to get an array of native values.
>
> An alternative, as you suggest, is to parse the string as source, because
> "BigInt strings with 'n' suffixes" are BigInt literals. Instead of "eval",
> the API functions to do that are Script::Compile and Script::Run. Look at
> samples/shell.cc or test/cctest/* for examples.
>
That works simply enough.
Would still have just preferred to have like ::NewFromUtf8 methods on Date
and BigInt; this seems like a LOT more overhead.
case JSOX_VALUE_BIGINT:
// just pass the string as is.
script = Script::Compile( String::NewFromUtf8( revive->isolate,
val->string, NewStringType::kNormal, val->stringLen ).ToLocalChecked()
, String::NewFromUtf8( revive->isolate, "BigIntFormater",
NewStringType::kInternalized ).ToLocalChecked() );
result = script->Run();
break;
case JSOX_VALUE_DATE:
char buf[64];
snprintf( buf, 64, "new Date('%s')", val->string );
script = Script::Compile( String::NewFromUtf8( revive->isolate, buf,
NewStringType::kNormal ).ToLocalChecked()
, String::NewFromUtf8( revive->isolate, "DateFormater",
NewStringType::kInternalized ).ToLocalChecked() );
result = script->Run();
break;
> Another alternative, depending on your requirements, might be to create
> this custom "parser" (more of a wrapper, really) in JavaScript:
>
> function MyBigInt(str) {
> console.assert(str.endsWith("n"));
> return BigInt(str.substring(0, str.length - 1));
> }
>
>
> On Sat, Sep 15, 2018 at 8:44 PM J Decker <[email protected]> wrote:
>
>>
>>
>> On Sat, Sep 15, 2018 at 8:41 PM J Decker <[email protected]> wrote:
>>
>>> I was implementing a parser that includes BigInt strings with 'n'
>>> suffixes...
>>> I tried to create a BigInt::New( isolate, ... and then found the only
>>> constructor takes an int64; which isn't a very big int.
>>>
>>> howto bigint from string?
>>>
>>
>> maybe someone could share a snippet to call eval()? Also Date::New()
>> doesn't take a string :(
>>
>>
>>> --
>>> --
>>> v8-users mailing list
>>> [email protected]
>>> http://groups.google.com/group/v8-users
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "v8-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> --
>> v8-users mailing list
>> [email protected]
>> http://groups.google.com/group/v8-users
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "v8-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.