ways to prevent scripts from accessing certain built-in features

28 views
Skip to first unread message

YJ

unread,
Apr 11, 2018, 12:58:16 AM4/11/18
to v8-users
Hi v8-users,

In certain situations we want user scripts to run in a context where the scripts don't get to use some of the newer ECMAScript features, for instance, Atomics, typed arrays etc. What is the recommended way to achieve that?

Any pointers are appreciated.

Ben Noordhuis

unread,
Apr 11, 2018, 5:13:37 AM4/11/18
to v8-users
Delete the corresponding globals from the global object
(`v8::Context::Global()`) before you start executing JS code. Won't
work for everything but will work for most things.

YJ

unread,
Apr 11, 2018, 7:30:00 AM4/11/18
to v8-users
Thanks Ben. Will give that a shot.

I had experimented with interceptors but unfortunately I can't seem to return a normal global object from inside an global interceptor as accessing a property triggers that interceptor again.

YJ

unread,
Apr 12, 2018, 4:29:30 AM4/12/18
to v8-users
A semi-related question, are the built-ins in global not enumerable for some reason ?

Basically the following code does not iterate over things like typed array constructors. Am I doing something wrong here ?

auto g = context->Global();  
Local<Array> props = g->GetPropertyNames();
const uint32_t length = props->Length(); // length is always 0 in a clean context

YJ

unread,
Apr 12, 2018, 4:56:05 AM4/12/18
to v8-users
Well nm...something along the following line works for me.

  // Local<Array> props = g->GetPropertyNames(context,
  //                                          KeyCollectionMode::kOwnOnly,
  //                                          PropertyFilter::ALL_PROPERTIES,
  //                                          IndexFilter::kSkipIndices)
  //   .ToLocalChecked();

The default mode for PropertyFilter must have been the problem.

Ben Noordhuis

unread,
Apr 12, 2018, 5:37:59 AM4/12/18
to v8-users
On Thu, Apr 12, 2018 at 10:29 AM, YJ <yang....@celigo.com> wrote:
> A semi-related question, are the built-ins in global not enumerable for some
> reason ?

That's per spec. Other JS engines work the same way.
Reply all
Reply to author
Forward
0 new messages