This repository was archived by the owner on Jul 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Feature reimpl arraybuffer #92
Open
kenny-y
wants to merge
2
commits into
intel:master
Choose a base branch
from
kenny-y:feature-reimpl-arraybuffer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Copyright (c) 2016 Intel Corporation. All rights reserved. | ||
| // Use of this source code is governed by a MIT-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "buffer.h" | ||
|
|
||
| #include <string.h> | ||
|
|
||
| Buffer::Buffer() { | ||
| data_ = "hello world!"; | ||
| } | ||
|
|
||
| Buffer::~Buffer() { | ||
| } | ||
|
|
||
| ArrayBufferHelper Buffer::getArrayBuffer() const { | ||
| char* text = "hello world!"; | ||
| return ArrayBufferHelper(text, strlen(text)); | ||
| } | ||
|
|
||
| ArrayBufferHelper Buffer::getCommonData() { | ||
| static char* raw_buf = "static buffer test data"; | ||
| return ArrayBufferHelper(raw_buf, strlen(raw_buf)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright (c) 2016 Intel Corporation. All rights reserved. | ||
| // Use of this source code is governed by a MIT-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef _BUFFER_H_ | ||
| #define _BUFFER_H_ | ||
|
|
||
| #include <node.h> | ||
| #include <v8.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "gen/generator_helper.h" | ||
|
|
||
| class Buffer { | ||
| public: | ||
| Buffer(); | ||
| ~Buffer(); | ||
|
|
||
| public: | ||
| ArrayBufferHelper getArrayBuffer() const; | ||
|
|
||
| ArrayBufferHelper get_data() const { | ||
| return ArrayBufferHelper( | ||
| const_cast<void*>(reinterpret_cast<const void*>(data_.c_str())), | ||
| data_.length()); | ||
| } | ||
|
|
||
| void set_data(const ArrayBufferHelper& buffer) { | ||
| data_ = std::string((const char*)buffer.GetData(), | ||
| buffer.GetLength()); | ||
| } | ||
|
|
||
| std::string buffer2String(const ArrayBufferHelper& arrayBuffer) { | ||
| return std::string((const char*)arrayBuffer.GetData(), | ||
| arrayBuffer.GetLength()); | ||
| } | ||
|
|
||
| static ArrayBufferHelper getCommonData(); | ||
|
|
||
| private: | ||
| std::string data_; | ||
| }; | ||
|
|
||
| #endif // _BUFFER_H_ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Copyright (c) 2016 Intel Corporation. All rights reserved. | ||
| // Use of this source code is governed by a MIT-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| /* global describe, it */ | ||
| var assert = require('assert'); | ||
| var buildAddon = require('../lib/addon-builder.js').buildAddon; | ||
| var compile = require('../lib/compile.js').compile; | ||
| var path = require('path'); | ||
|
|
||
| var Buffer; | ||
|
|
||
| function bufToString(buf) { | ||
| return String.fromCharCode.apply(null, new Uint8Array(buf)); | ||
| } | ||
|
|
||
| function stringToArrayBuffer(str) { | ||
| var buf = new ArrayBuffer(str.length); | ||
| var bufView = new Uint8Array(buf); | ||
| for (var i = 0, strLen = str.length; i < strLen; ++i) { | ||
| bufView[i] = str.charCodeAt(i); | ||
| } | ||
| return buf; | ||
| } | ||
|
|
||
| describe('widl-nan Unit Test - Buffer', function() { | ||
| it('Generating binding C++ code', function() { | ||
| return compile([ | ||
| 'test/arraybuffer/arraybuffer.widl' | ||
| ], 'test/arraybuffer/gen'); | ||
| }); | ||
|
|
||
| it('Building addon', function() { | ||
| // building addon maybe slow | ||
| this.timeout(100000); | ||
|
|
||
| return buildAddon('test/arraybuffer'); | ||
| }); | ||
|
|
||
| it('Loading addon', function() { | ||
| var addonDir = path.join(path.dirname(__filename), 'arraybuffer'); | ||
| var addon = require('bindings')( | ||
| // eslint-disable-next-line camelcase | ||
| {bindings: 'testerAddon', module_root: addonDir}); | ||
|
|
||
| Buffer = addon.Buffer; | ||
| assert.equal(typeof Buffer, 'function'); | ||
| }); | ||
|
|
||
| it('Method returning an ArrayBuffer', done => { | ||
| var buf = new Buffer(); | ||
| assert.equal(bufToString(buf.getArrayBuffer()), 'hello world!'); | ||
| done(); | ||
| }); | ||
|
|
||
| it('Static method returning an ArrayBuffer', done => { | ||
| assert.equal(bufToString(Buffer.getCommonData()), 'static buffer test data'); | ||
| assert.equal(bufToString(Buffer.getCommonData()), 'static buffer test data'); | ||
| assert.equal(bufToString(Buffer.getCommonData()), 'static buffer test data'); | ||
| done(); | ||
| }); | ||
|
|
||
| it('Object property as ArrayBuffer', done => { | ||
| var buf = new Buffer(); | ||
| assert.equal(bufToString(buf.data), 'hello world!'); | ||
| buf.data = stringToArrayBuffer('hello universe!'); | ||
| assert.equal(bufToString(buf.data), 'hello universe!'); | ||
| done(); | ||
| }); | ||
|
|
||
| it('Passing ArrayBuffer as paramter', done => { | ||
| var buf = new Buffer(); | ||
| const buffer = stringToArrayBuffer('Array buffer string test...'); | ||
| assert.equal(buf.buffer2String(buffer), 'Array buffer string test...'); | ||
| done(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the buffer copy using assign cause multiple free if the mode is internal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes if
external_buffer_isfalse, then there can be double delete problem, unless user explicitly change one object and set itsexternal_buffertotrueCan there be an automatically approach to avoid this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove the const to change the rhs? Seems not compatible with the coding style. :)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we rename the class to
ExternalArrayBufferand make it only work inexternal buffer mode?ArrayBuffers with ownership of buffer will be treated in other class, to avoid potential issues.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The choice of whether ExternalArrayBuffer or InternalArrayBuffer is made only in impl code right? I'm ok with that.