New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap v8::Object::GetPrivate #587

Closed
cscott opened this Issue Jun 29, 2016 · 6 comments

Comments

Projects
None yet
5 participants
@cscott

cscott commented Jun 29, 2016

v8 renamed v8::Object::SetHiddenValue/GetHiddenValue/DeleteHiddenValue to v8::Object::GetPrivate/SetPrivate/DeletePrivate (and added HasPrivate) and changed the return types from Local to MaybeLocal. Seems like this is a good candidate for wrapping with nan, especially since the very latest versions of v8 seem to have deleted the old SetHiddenValue versions, which will break a lot of my modules. (This change hasn't quite made it into node yet AFAICT.)

@kkoopa kkoopa added this to the 3.0 milestone Jun 29, 2016

@kkoopa

This comment has been minimized.

Collaborator

kkoopa commented Jun 29, 2016

Since that change will break ABI compatibility, Node will not use it until v7, which is scheduled for some time in autumn. This will be taken care of then.

@maxkorp

This comment has been minimized.

Contributor

maxkorp commented Aug 11, 2016

So unfortunately electron (as of 1.3) has already jumped to v8 5.2.x.y, in which this is broken, and also seems to have a different signature (key/value, instead of context/key/value).

They seem to have a wrapper for the methods here:
https://github.com/electron/electron/blob/faf896db6726aad7995595a73a93aca1ccaf7dfa/atom/common/api/atom_api_v8_util.cc#L51-L85

@maxkorp

This comment has been minimized.

Contributor

maxkorp commented Aug 11, 2016

Obviously, this is not set up using the global exported version constants and is not out in it's own file or anything of the sort, but the gist of what we've ended up with in nodegit to fix this is as such

#if (NODE_MODULE_VERSION > 48)
  v8::Local<v8::Value> GetPrivate(v8::Local<v8::Object> object,
                                  v8::Local<v8::String> key) {
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    v8::Local<v8::Context> context = isolate->GetCurrentContext();
    v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, key);
    v8::Local<v8::Value> value;
    v8::Maybe<bool> result = object->HasPrivate(context, privateKey);
    if (!(result.IsJust() && result.FromJust()))
      return v8::Local<v8::Value>();
    if (object->GetPrivate(context, privateKey).ToLocal(&value))
      return value;
    return v8::Local<v8::Value>();
  }

  void SetPrivate(v8::Local<v8::Object> object,
                  v8::Local<v8::String> key,
                  v8::Local<v8::Value> value) {
    if (value.IsEmpty())
      return;
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    v8::Local<v8::Context> context = isolate->GetCurrentContext();
    v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, key);
    object->SetPrivate(context, privateKey, value);
  }
#else
  v8::Local<v8::Value> GetPrivate(v8::Local<v8::Object> object,
                                      v8::Local<v8::String> key) {
    return object->GetHiddenValue(key);
  }

  void SetPrivate(v8::Local<v8::Object> object,
                      v8::Local<v8::String> key,
                      v8::Local<v8::Value> value) {
    object->SetHiddenValue(key, value);
  }
#endif

called like

Local<v8::Value> checkValue = Nan::GetPrivate(nodeObj, Nan::New("BlahBlah").ToLocalChecked());
@bnoordhuis

This comment has been minimized.

Member

bnoordhuis commented Aug 12, 2016

I wouldn't reject patches for 5.2 out of hand but there is no way for us to test them (I think. Perhaps building against Electron could be tested but running the suite on the CI? Probably not.)

@maxkorp

This comment has been minimized.

Contributor

maxkorp commented Aug 12, 2016

So, I've tested locally with electron, but I'll take a look at how the tests for this run and see if I can work up an electron solution for the short term 👍

@saper

This comment has been minimized.

Contributor

saper commented Aug 18, 2016

New methods could be used already for node 6.x, running V8 v5.0.x.

victorwins added a commit to victorwins/electron-clr that referenced this issue Oct 4, 2016

ver. 1.4.2
* Electron 1.4.2
* SetPrivate/GetPrivate from nodejs/nan#587
* debug logs commented out

@mdlavin mdlavin referenced this issue Nov 14, 2016

Closed

Support node 7 #132

@kkoopa kkoopa closed this Dec 30, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment