#291 Open

Bitbucket cannot automatically merge this request.

The commits that make up this pull request have been removed.

Bitbucket cannot automatically merge this request due to conflicts.

Review the conflicts on the Overview tab. You can then either decline the request or merge it manually on your local system using the following commands:

git checkout master
git remote add vmas/cef https://bitbucket.org/vmas/cef.git
git fetch vmas/cef
git merge --no-ff -m 'Merged in vmas/cef/improve-cefv8value-t (pull request #291)' remotes/vmas/cef/improve-cefv8value-t
  1. Vladislav
  1. Added CefV8Value::GetObjectIdentityHash. This function provides a hash for values of the following types: Object, Symbol, and BigInt.
  2. Added basic support for BigInt and Symbol;
  3. Reduced the size of the _cef_v8value_t. I replaced the type checking functions with _cef_v8value_t::get_type and _cef_v8value_t::is_object_of_type. For compatibility with legacy code the CefV8Value::Is* functions are saved in the C++ API.

Comments (2)

  1. Marshall Greenblatt

    Can you explain the use case for GetObjectIdentityHash? From the V8 documentation is sounds like this value is not guaranteed to be unique.

    1. Vladislav author

      The GetObjectIdentityHash provides a hash code for algorithms that need quick checks of V8 object equality. There is no unique identifier for an V8 object. But GetObjectIdentityHash enough to build hash maps, hash tables, sets for CefV8Value's. Currently, the only legal way to find equal CefV8Value's is to CefV8Value::IsSame against every single object in the table, which is very slow if there are a lot of objects to keep track of. With simple CefV8Value types like int, string, time there is no problem - is to compute a hash for their value. As usual, when using hash functions, collisions can occur, the algorithm should check objects with the same hash codes for equality.

      In my case, I use a cache for the C API wrappers. I compute a hash for cef_v8value_t and use it as a hash for a key to insert into a dictionary that contains weak references to .NET wrappers around cef_v8value_t. Unlike other CEF objects the CefV8Value instances are always new even for the same V8 object. Unable to get any identifier for them by raw pointer to CefV8Value. If CEF binary distribution from Spotify are used, then only somehow working way available to me now is to read from the memory the value of CefV8ValueImpl::handle ->GetPersistentV8Handle().val_. This approach is very bad because it depends on how several structures are stored in memory. The GetObjectIdentityHash is a good way to identify in this case.