Skip to content

Commit

Permalink
use GetBackingStore() instead of GetContents() (#888)
Browse files Browse the repository at this point in the history
* use GetBackingStore() instead of GetContents()

Use GetBackingStore() instead of GetContents() for v8 >= 8.0
as GetContents() has been deprecated. Node.js 14 will use 8.1

It would be possible to use GetBackingStore() already with 7.9
but this would lead to issues with Node.js 13 as it uses 7.8
till 13.2.0.

Additionally update testmatrix to use latest electron versions
and add electron 8.

Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
Flarna and bnoordhuis committed Mar 6, 2020
1 parent 2c4ee8a commit 2c023bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ env:
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="2.0.18"
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="3.1.13"
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="4.2.12"
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="5.0.11"
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="6.1.2"
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="7.0.0"
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="5.0.13"
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="6.1.9"
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="7.1.14"
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="8.0.3"
matrix:
exclude:
- os: osx
Expand Down
8 changes: 7 additions & 1 deletion nan_typedarray_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ class TypedArrayContents {
v8::Local<v8::ArrayBuffer> buffer = array->Buffer();

length = byte_length / sizeof(T);
data = static_cast<char*>(buffer->GetContents().Data()) + byte_offset;
// Actually it's 7.9 here but this would lead to ABI issues with Node.js 13
// using 7.8 till 13.2.0.
#if (V8_MAJOR_VERSION >= 8)
data = static_cast<char*>(buffer->GetBackingStore()->Data()) + byte_offset;
#else
data = static_cast<char*>(buffer->GetContents().Data()) + byte_offset;
#endif
}

#else
Expand Down

5 comments on commit 2c023bd

@Xing1P
Copy link

@Xing1P Xing1P commented on 2c023bd Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to fix this problem? Please help
error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class v8::BackingStore> __cdecl v8::ArrayBuffer::GetBackingStore(void)"

Note: - Electron 13.0.0

@Jiahui-Yan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to fix this problem? Please help
error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class v8::BackingStore> __cdecl v8::ArrayBuffer::GetBackingStore(void)"

Note: - Electron 13.0.0

I have the same problem, and I found that in Electron 12.0.9 you can use GetContents methods instead.

@GitMurf
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Xing1P or @Jiahui-Yan did you ever come up with a solution / workaround for Electron 13+?

@Jiahui-Yan
Copy link

@Jiahui-Yan Jiahui-Yan commented on 2c023bd Dec 13, 2022 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GitMurf
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jiahui-Yan thank you for the reply. I have been trying to figure out how to convert node-canvas from NaN to n-api via node-addon-api but have had no luck. Do you have any advice? Any good resources / tutorials? Thanks!

Please sign in to comment.