+1 to Leszek's suggestion. Getting rid of properties on the global object
is easy, even without modifying V8 at all: for example, delete Array gets
rid of the Array builtin, so var a = new Array(1) will throw ReferenceError:
Array is not defined. However, disabling the corresponding internal
functionality is much harder, and e.g. var a = [42] will still work fine.
Figuring out all the places where V8 would have to be hacked to trim its
supported language down to what you want is probably at least as hard as
writing an evaluator from scratch. And it *definitely* wouldn't work
without recompiling V8 (many times even, during development).

On Fri, Jan 31, 2020 at 9:32 AM Leszek Swirski <[email protected]> wrote:

> If all you want is binary operations and comparisons on numbers and
> strings, then it could be a fun (and educational!) weekend project to write
> an infix expression evaluator and drop the V8 dependency entirely. That
> might be easier than trying to bend a JS engine into evaluating only such a
> tiny subset of JS.
>
> - Leszek
>
> On Fri, 31 Jan 2020, 08:34 'Simon Zünd' via v8-dev, <
> [email protected]> wrote:
>
>> As stated earlier, V8 itself was never meant to be used this way, so
>> there is currently no way to specify a subset of JavaScript that V8 would
>> allow.
>>
>> As an alternative, you could run your scripts through an existing
>> JavaScript parser (acorn, esprima, etc), walk the resulting AST and throw
>> on all the language constructs you want to forbid. Before passing the
>> actual source along to V8.
>>
>> On Fri, Jan 31, 2020 at 8:17 AM <[email protected]> wrote:
>>
>>> Hi Thanks for the help. Currently i am using prebuilt v8 binaries from
>>> nuget package https://github.com/pmed/v8-nuget  in windows.
>>>  Is there any other way rather building the V8 and generating binaries.
>>>
>>> I already have  prebuilt v8 binaries and bin(snapshotblob and
>>> nativeblob) files from nuget package.
>>> can we do some thing in code to exclude those built-in functionality in
>>> V8 engine?
>>>
>>> for eg:
>>> in js script, if i type
>>> 1) Date();    //V8 engine should show error rather than showing date.
>>>
>>> 2) var newarray = new Array();    var arr = [1,2,3,4,5];
>>>    // v8 engine should not allow creating dynamic elements.
>>>
>>> 3) var  newObject = {  "name"="xyz", "age"=5 };
>>>     var newObject = Object.create( Object.prototype );
>>>    // v8 engine should not allow  object oriented programming .
>>>
>>> 4) function add(a,b)
>>> {
>>>        return a+b;
>>> }
>>> var res = add(2,3);
>>>  // v8 engine should not allow users to create functions.
>>>
>>> My requirement is simple comparison and returning Boolean value
>>>
>>> 5 > 3 &&  4==10  ||   "abc" =="xyz;
>>>
>>> i am gonna register the callbackfunctions in c++ and get the value after
>>> running the script, evaluate and print the boolean result.
>>>
>>>
>>> Could you please help me how can i achieve this.
>>>
>>> On Friday, January 31, 2020 at 10:50:48 AM UTC+5:30, [email protected]
>>> wrote:
>>>>
>>>> I am trying to embed engine in c++ application. i don't want the
>>>> java-script  built-in Methods and functions.
>>>> I need it only for arithmetic and relational operators.
>>>>
>>>> after exploring much in internet ,i got to know built-ins functions are
>>>> de-serilized and put in from these native_blob.bin and snapshot_blob.bin .
>>>> I commented v8::V8::InitializeExternalStartupData(argv[0]); , but
>>>> throwing some run-time error.
>>>>
>>>> Could anyone please help me on this.
>>>>
>>>> Requirement : Embedding v8 engine without built-in functionality as i
>>>> need it only for arithmetic, relational operators.
>>>> I don't want these builts-in function gets de-serialized and put in
>>>> heap (
>>>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
>>>> )
>>>>
>>>>
>>>> References:
>>>> 1) https://v8.dev/blog/embedded-builtins.
>>>> 2) https://v8.dev/blog/custom-startup-snapshots
>>>> 3) https://v8.dev/docs/builtin-functions
>>>> 4) https://v8.dev/blog/lazy-deserialization
>>>>
>>>> Thanks & Regards
>>>> Praveen N
>>>>
>>>>
>>> --
>>
>>

-- 
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/CAKSzg3QUChn2MgTGyWDecF2mi0i8TXwLm_-CUhcfdTRKmt9-%3DA%40mail.gmail.com.

Reply via email to