msgpackr-extract 1.0.15 → 1.0.16-napi.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +19 -0
- package/.github/workflows/prebuild.yml +71 -5
- package/.travis.yml +30 -30
- package/.vscode/launch.json +15 -0
- package/binding.gyp +3 -3
- package/package.json +8 -10
- package/prebuilds/darwin-arm64/{node.abi83.node → node.napi.glibc.node} +0 -0
- package/prebuilds/darwin-x64/{node.abi83.node → node.napi.node} +0 -0
- package/prebuilds/linux-arm64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/linux-x64/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/extract.cpp +89 -67
- package/.prebuilds.tmp/prebuilds/darwin-arm64/node.abi102.node +0 -0
- package/.prebuilds.tmp/prebuilds/darwin-arm64/node.abi83.node +0 -0
- package/.prebuilds.tmp/prebuilds/darwin-arm64/node.abi93.node +0 -0
- package/.prebuilds.tmp/prebuilds/darwin-x64/node.abi102.node +0 -0
- package/.prebuilds.tmp/prebuilds/darwin-x64/node.abi72.node +0 -0
- package/.prebuilds.tmp/prebuilds/darwin-x64/node.abi83.node +0 -0
- package/.prebuilds.tmp/prebuilds/darwin-x64/node.abi93.node +0 -0
- package/prebuilds/darwin-arm64/node.abi102.node +0 -0
- package/prebuilds/darwin-arm64/node.abi93.node +0 -0
- package/prebuilds/darwin-x64/node.abi102.node +0 -0
- package/prebuilds/darwin-x64/node.abi72.node +0 -0
- package/prebuilds/darwin-x64/node.abi93.node +0 -0
- package/prebuilds/linux-arm64/node.abi72.node +0 -0
- package/prebuilds/linux-arm64/node.abi83.node +0 -0
- package/prebuilds/linux-arm64/node.abi93.node +0 -0
- package/prebuilds/linux-x64/node.abi72.node +0 -0
- package/prebuilds/linux-x64/node.abi83.node +0 -0
- package/prebuilds/linux-x64/node.abi93.node +0 -0
- package/prebuilds/win32-x64/electron.abi89.node +0 -0
- package/prebuilds/win32-x64/node.abi102.node +0 -0
- package/prebuilds/win32-x64/node.abi72.node +0 -0
- package/prebuilds/win32-x64/node.abi83.node +0 -0
- package/prebuilds/win32-x64/node.abi93.node +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: Test and Prebuild
|
|
2
|
+
jobs:
|
|
3
|
+
build:
|
|
4
|
+
executor: my-ubuntu-exec
|
|
5
|
+
steps:
|
|
6
|
+
- uses: actions/checkout@v2
|
|
7
|
+
- name: Setup node
|
|
8
|
+
uses: actions/setup-node@v2
|
|
9
|
+
with:
|
|
10
|
+
node-version: 12
|
|
11
|
+
- run: npm install
|
|
12
|
+
- run: npm run prebuild
|
|
13
|
+
- run: zip -r prebuild-darwin.zip prebuilds
|
|
14
|
+
- run: hexdump "prebuilds/darwin-x64/node.abi93.node" | head -10
|
|
15
|
+
- name: Prebuild
|
|
16
|
+
uses: softprops/action-gh-release@v1
|
|
17
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
18
|
+
with:
|
|
19
|
+
files: prebuild-darwin.zip
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
name:
|
|
1
|
+
name: Prebuild
|
|
2
2
|
on: [push]
|
|
3
3
|
jobs:
|
|
4
|
-
build:
|
|
4
|
+
build-test-macos:
|
|
5
5
|
if: startsWith(github.ref, 'refs/tags/')
|
|
6
6
|
runs-on: macos-11
|
|
7
7
|
steps:
|
|
@@ -11,11 +11,77 @@ jobs:
|
|
|
11
11
|
with:
|
|
12
12
|
node-version: 12
|
|
13
13
|
- run: npm install
|
|
14
|
+
- run: npm test
|
|
14
15
|
- run: npm run prebuild
|
|
15
|
-
|
|
16
|
-
- run:
|
|
16
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
17
|
+
- run: npm run prebuild-arm64
|
|
18
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
19
|
+
- run: tar --create --format ustar --verbose --file=prebuild-darwin.tar -C prebuilds .
|
|
20
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
21
|
+
- name: Prebuild
|
|
22
|
+
uses: softprops/action-gh-release@v1
|
|
23
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
24
|
+
with:
|
|
25
|
+
files: prebuild-darwin.tar
|
|
26
|
+
build-centos-7:
|
|
27
|
+
#if: startsWith(github.ref, 'refs/tags/')
|
|
28
|
+
runs-on: ubuntu-18.04
|
|
29
|
+
container: quay.io/pypa/manylinux2014_x86_64
|
|
30
|
+
steps:
|
|
31
|
+
- run: ldd --version ldd
|
|
32
|
+
- uses: actions/checkout@v2
|
|
33
|
+
- name: Setup node
|
|
34
|
+
uses: actions/setup-node@v2
|
|
35
|
+
with:
|
|
36
|
+
node-version: 12
|
|
37
|
+
- run: npm install
|
|
38
|
+
- run: npm run prebuild
|
|
39
|
+
- run: npm test
|
|
40
|
+
- run: tar --create --verbose --file=prebuild-linux.tar -C prebuilds .
|
|
41
|
+
- name: Prebuild
|
|
42
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
43
|
+
uses: softprops/action-gh-release@v1
|
|
44
|
+
with:
|
|
45
|
+
files: prebuild-linux.tar
|
|
46
|
+
build-alpine:
|
|
47
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
48
|
+
runs-on: ubuntu-18.04
|
|
49
|
+
container: node:12-alpine
|
|
50
|
+
steps:
|
|
51
|
+
- run: apk add python3 py3-pip build-base
|
|
52
|
+
- uses: actions/checkout@v2
|
|
53
|
+
- run: npm install
|
|
54
|
+
- run: npm run prebuild-musl
|
|
55
|
+
- run: npm test
|
|
56
|
+
- run: tar --create --verbose --file=prebuild-alpine.tar -C prebuilds .
|
|
17
57
|
- name: Prebuild
|
|
58
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
18
59
|
uses: softprops/action-gh-release@v1
|
|
60
|
+
with:
|
|
61
|
+
files: prebuild-alpine.tar
|
|
62
|
+
build-linux-arm64:
|
|
63
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
64
|
+
runs-on: ubuntu-18.04
|
|
65
|
+
container: quay.io/pypa/manylinux_2_24_x86_64
|
|
66
|
+
steps:
|
|
67
|
+
- run: apt-get update
|
|
68
|
+
- run: apt-get install -y gcc-aarch64-linux-gnu
|
|
69
|
+
- run: apt-get install -y g++-aarch64-linux-gnu
|
|
70
|
+
- run: ldd --version ldd
|
|
71
|
+
- uses: actions/checkout@v2
|
|
72
|
+
- name: Setup node
|
|
73
|
+
uses: actions/setup-node@v2
|
|
74
|
+
with:
|
|
75
|
+
node-version: 12
|
|
76
|
+
- run: npm install
|
|
77
|
+
- run: npm run prebuild-arm64
|
|
78
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
79
|
+
env:
|
|
80
|
+
CC: aarch64-linux-gnu-gcc
|
|
81
|
+
CXX: aarch64-linux-gnu-g++
|
|
82
|
+
- run: tar --create --verbose --file=prebuild-linux-arm64.tar -C prebuilds .
|
|
83
|
+
- name: Prebuild
|
|
19
84
|
if: startsWith(github.ref, 'refs/tags/')
|
|
85
|
+
uses: softprops/action-gh-release@v1
|
|
20
86
|
with:
|
|
21
|
-
files: prebuild-
|
|
87
|
+
files: prebuild-linux-arm64.tar
|
package/.travis.yml
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
sudo: false
|
|
2
|
-
language: node_js
|
|
3
|
-
node_js:
|
|
4
|
-
- node
|
|
5
|
-
addons:
|
|
6
|
-
apt:
|
|
7
|
-
sources:
|
|
8
|
-
- ubuntu-toolchain-r-test
|
|
9
|
-
arch:
|
|
10
|
-
- amd64
|
|
11
|
-
- arm64
|
|
12
|
-
os:
|
|
13
|
-
- osx
|
|
14
|
-
- linux
|
|
15
|
-
osx_image: xcode12.5
|
|
16
|
-
before_deploy:
|
|
17
|
-
- ARCHIVE_NAME="${TRAVIS_TAG:-latest}-$TRAVIS_OS_NAME-`uname -m`.tar"
|
|
18
|
-
- npm run prebuild
|
|
19
|
-
- tar --create --verbose --file="$ARCHIVE_NAME" --directory "$TRAVIS_BUILD_DIR/prebuilds"
|
|
20
|
-
.
|
|
21
|
-
deploy:
|
|
22
|
-
provider: releases
|
|
23
|
-
draft: false
|
|
24
|
-
prerelease: true
|
|
25
|
-
file: "$ARCHIVE_NAME"
|
|
26
|
-
skip_cleanup: true
|
|
27
|
-
on:
|
|
28
|
-
tags: true
|
|
29
|
-
node: node
|
|
30
|
-
api_key: '$GITHUB_API_KEY'
|
|
1
|
+
sudo: false
|
|
2
|
+
language: node_js
|
|
3
|
+
node_js:
|
|
4
|
+
- node
|
|
5
|
+
addons:
|
|
6
|
+
apt:
|
|
7
|
+
sources:
|
|
8
|
+
- ubuntu-toolchain-r-test
|
|
9
|
+
arch:
|
|
10
|
+
- amd64
|
|
11
|
+
- arm64
|
|
12
|
+
os:
|
|
13
|
+
- osx
|
|
14
|
+
- linux
|
|
15
|
+
osx_image: xcode12.5
|
|
16
|
+
before_deploy:
|
|
17
|
+
- ARCHIVE_NAME="${TRAVIS_TAG:-latest}-$TRAVIS_OS_NAME-`uname -m`.tar"
|
|
18
|
+
- npm run prebuild
|
|
19
|
+
- tar --create --verbose --file="$ARCHIVE_NAME" --directory "$TRAVIS_BUILD_DIR/prebuilds"
|
|
20
|
+
.
|
|
21
|
+
deploy:
|
|
22
|
+
provider: releases
|
|
23
|
+
draft: false
|
|
24
|
+
prerelease: true
|
|
25
|
+
file: "$ARCHIVE_NAME"
|
|
26
|
+
skip_cleanup: true
|
|
27
|
+
on:
|
|
28
|
+
tags: true
|
|
29
|
+
node: node
|
|
30
|
+
api_key: '$GITHUB_API_KEY'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"name": "(Windows) Attach",
|
|
9
|
+
"type": "cppvsdbg",
|
|
10
|
+
"request": "attach",
|
|
11
|
+
"processId": "${command:pickProcess}",
|
|
12
|
+
"internalConsoleOptions": "neverOpen"
|
|
13
|
+
},
|
|
14
|
+
]
|
|
15
|
+
}
|
package/binding.gyp
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"sources": [
|
|
11
11
|
"src/extract.cpp",
|
|
12
12
|
],
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
],
|
|
13
|
+
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
|
|
14
|
+
"include_dirs" : ["<!(node -p \"require('node-addon-api').include_dir\")"],
|
|
15
|
+
"dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
|
|
16
16
|
"conditions": [
|
|
17
17
|
["OS=='linux'", {
|
|
18
18
|
"variables": {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msgpackr-extract",
|
|
3
3
|
"author": "Kris Zyp",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.16-napi.1",
|
|
5
5
|
"description": "Node addon for string extraction for msgpackr",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -11,22 +11,20 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"install": "node-gyp-build",
|
|
13
13
|
"recompile": "node-gyp build",
|
|
14
|
-
"
|
|
15
|
-
"prebuild
|
|
16
|
-
"prebuild
|
|
17
|
-
"
|
|
18
|
-
"test-prebuild": "prebuildify --target 16.9.0",
|
|
14
|
+
"before-publish": "prebuildify-ci download && prebuildify --napi --target 12.22.7",
|
|
15
|
+
"prebuild": "prebuildify --napi --target 12.22.7",
|
|
16
|
+
"prebuild-musl": "prebuildify --napi --libc musl --tag-libc --target 12.22.7",
|
|
17
|
+
"prebuild-arm64": "prebuildify --napi --arch=arm64 --tag-libc --target 12.22.7",
|
|
19
18
|
"test": ""
|
|
20
19
|
},
|
|
21
20
|
"main": "./index.js",
|
|
22
21
|
"gypfile": true,
|
|
23
22
|
"dependencies": {
|
|
24
|
-
"
|
|
23
|
+
"node-addon-api": "^4.3.0",
|
|
25
24
|
"node-gyp-build": "^4.2.3"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
|
-
"prebuildify": "
|
|
29
|
-
"prebuildify-ci": "^1.0.5"
|
|
30
|
-
"run-script-os": "^1.1.6"
|
|
27
|
+
"prebuildify": "^5.0.0",
|
|
28
|
+
"prebuildify-ci": "^1.0.5"
|
|
31
29
|
}
|
|
32
30
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/extract.cpp
CHANGED
|
@@ -6,10 +6,10 @@ times as necessary to get more strings. This must be partially capable of parsin
|
|
|
6
6
|
find the string tokens and determine their position and length. All strings are decoded as UTF-8.
|
|
7
7
|
*/
|
|
8
8
|
#include <v8.h>
|
|
9
|
-
#include <
|
|
10
|
-
#include <
|
|
11
|
-
|
|
12
|
-
using namespace
|
|
9
|
+
#include <napi.h>
|
|
10
|
+
#include <node_api.h>
|
|
11
|
+
|
|
12
|
+
using namespace Napi;
|
|
13
13
|
|
|
14
14
|
#ifndef thread_local
|
|
15
15
|
#ifdef __GNUC__
|
|
@@ -24,7 +24,7 @@ using namespace v8;
|
|
|
24
24
|
#endif
|
|
25
25
|
|
|
26
26
|
const int MAX_TARGET_SIZE = 255;
|
|
27
|
-
typedef int (*token_handler)(uint8_t* source, int position, int size);
|
|
27
|
+
typedef int (*token_handler)(Env env, uint8_t* source, int position, int size);
|
|
28
28
|
token_handler tokenTable[256] = {};
|
|
29
29
|
class Extractor {
|
|
30
30
|
public:
|
|
@@ -35,8 +35,9 @@ public:
|
|
|
35
35
|
int writePosition = 0;
|
|
36
36
|
int stringStart = 0;
|
|
37
37
|
int lastStringEnd = 0;
|
|
38
|
-
Isolate *isolate = Isolate::GetCurrent();
|
|
39
|
-
|
|
38
|
+
v8::Isolate *isolate = v8::Isolate::GetCurrent();
|
|
39
|
+
|
|
40
|
+
void readString(Env env, int length, bool allowStringBlocks) {
|
|
40
41
|
int start = position;
|
|
41
42
|
int end = position + length;
|
|
42
43
|
if (allowStringBlocks) { // for larger strings, we don't bother to check every character for being latin, and just go right to creating a new string
|
|
@@ -51,18 +52,18 @@ public:
|
|
|
51
52
|
if (position < end) {
|
|
52
53
|
// non-latin character
|
|
53
54
|
if (lastStringEnd) {
|
|
54
|
-
target[writePosition++] = String::NewFromOneByte(isolate, (uint8_t*) source + stringStart, v8::NewStringType::kNormal, lastStringEnd - stringStart).ToLocalChecked();
|
|
55
|
+
target[writePosition++] = v8::String::NewFromOneByte(isolate, (uint8_t*) source + stringStart, v8::NewStringType::kNormal, lastStringEnd - stringStart).ToLocalChecked();
|
|
55
56
|
lastStringEnd = 0;
|
|
56
57
|
}
|
|
57
58
|
// use standard utf-8 conversion
|
|
58
|
-
target[writePosition++] =
|
|
59
|
+
target[writePosition++] = v8::String::NewFromUtf8(isolate, (char*) source + start, v8::NewStringType::kNormal, length).ToLocalChecked();
|
|
59
60
|
position = end;
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
if (lastStringEnd) {
|
|
64
65
|
if (start - lastStringEnd > 40 || end - stringStart > 6000) {
|
|
65
|
-
target[writePosition++] = String::NewFromOneByte(isolate, (uint8_t*) source + stringStart, v8::NewStringType::kNormal, lastStringEnd - stringStart).ToLocalChecked();
|
|
66
|
+
target[writePosition++] = v8::String::NewFromOneByte(isolate, (uint8_t*) source + stringStart, v8::NewStringType::kNormal, lastStringEnd - stringStart).ToLocalChecked();
|
|
66
67
|
stringStart = start;
|
|
67
68
|
}
|
|
68
69
|
} else {
|
|
@@ -71,7 +72,7 @@ public:
|
|
|
71
72
|
lastStringEnd = end;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
|
|
75
|
+
napi_value extractStrings(Env env, int startingPosition, int size, uint8_t* inputSource) {
|
|
75
76
|
writePosition = 0;
|
|
76
77
|
lastStringEnd = 0;
|
|
77
78
|
position = startingPosition;
|
|
@@ -84,50 +85,50 @@ public:
|
|
|
84
85
|
// fixstr, we want to convert this
|
|
85
86
|
token -= 0xa0;
|
|
86
87
|
if (token + position > size) {
|
|
87
|
-
|
|
88
|
-
return
|
|
88
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
89
|
+
return env.Null();
|
|
89
90
|
}
|
|
90
|
-
readString(token, true);
|
|
91
|
+
readString(env,token, true);
|
|
91
92
|
if (writePosition >= MAX_TARGET_SIZE)
|
|
92
93
|
break;
|
|
93
94
|
} else if (token <= 0xdb && token >= 0xd9) {
|
|
94
95
|
if (token == 0xd9) { //str 8
|
|
95
96
|
if (position >= size) {
|
|
96
|
-
|
|
97
|
-
return
|
|
97
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
98
|
+
return env.Null();
|
|
98
99
|
}
|
|
99
100
|
int length = source[position++];
|
|
100
101
|
if (length + position > size) {
|
|
101
|
-
|
|
102
|
-
return
|
|
102
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
103
|
+
return env.Null();
|
|
103
104
|
}
|
|
104
|
-
readString(length, true);
|
|
105
|
+
readString(env,length, true);
|
|
105
106
|
} else if (token == 0xda) { //str 16
|
|
106
107
|
if (2 + position > size) {
|
|
107
|
-
|
|
108
|
-
return
|
|
108
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
109
|
+
return env.Null();
|
|
109
110
|
}
|
|
110
111
|
int length = source[position++] << 8;
|
|
111
112
|
length += source[position++];
|
|
112
113
|
if (length + position > size) {
|
|
113
|
-
|
|
114
|
-
return
|
|
114
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
115
|
+
return env.Null();
|
|
115
116
|
}
|
|
116
|
-
readString(length, false);
|
|
117
|
+
readString(env,length, false);
|
|
117
118
|
} else { //str 32
|
|
118
119
|
if (4 + position > size) {
|
|
119
|
-
|
|
120
|
-
return
|
|
120
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
121
|
+
return env.Null();
|
|
121
122
|
}
|
|
122
123
|
int length = source[position++] << 24;
|
|
123
124
|
length += source[position++] << 16;
|
|
124
125
|
length += source[position++] << 8;
|
|
125
126
|
length += source[position++];
|
|
126
127
|
if (length + position > size) {
|
|
127
|
-
|
|
128
|
-
return
|
|
128
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
129
|
+
return env.Null();
|
|
129
130
|
}
|
|
130
|
-
readString(length, false);
|
|
131
|
+
readString(env, length, false);
|
|
131
132
|
}
|
|
132
133
|
if (writePosition >= MAX_TARGET_SIZE)
|
|
133
134
|
break;
|
|
@@ -136,35 +137,43 @@ public:
|
|
|
136
137
|
if ((size_t ) handle < 20) {
|
|
137
138
|
position += (size_t ) handle;
|
|
138
139
|
} else {
|
|
139
|
-
position = tokenTable[token](source, position, size);
|
|
140
|
+
position = tokenTable[token](env, source, position, size);
|
|
140
141
|
if (position < 0) {
|
|
141
|
-
|
|
142
|
-
return
|
|
142
|
+
TypeError::New(env, "Unexpected end of buffer").ThrowAsJavaScriptException();
|
|
143
|
+
return env.Null();
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
|
-
|
|
148
|
+
v8::Local<v8::Value> v8ReturnValue;
|
|
148
149
|
if (lastStringEnd) {
|
|
149
|
-
if (writePosition == 0)
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
if (writePosition == 0) {
|
|
151
|
+
v8ReturnValue = v8::String::NewFromOneByte(isolate, (uint8_t*) source + stringStart, v8::NewStringType::kNormal, lastStringEnd - stringStart).ToLocalChecked();
|
|
152
|
+
goto done;
|
|
153
|
+
}
|
|
154
|
+
target[writePosition++] = v8::String::NewFromOneByte(isolate, (uint8_t*) source + stringStart, v8::NewStringType::kNormal, lastStringEnd - stringStart).ToLocalChecked();
|
|
152
155
|
} else if (writePosition == 1) {
|
|
153
|
-
|
|
156
|
+
v8ReturnValue = target[0];
|
|
157
|
+
goto done;
|
|
154
158
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
159
|
+
//#if NODE_VERSION_AT_LEAST(12,0,0)
|
|
160
|
+
v8ReturnValue = v8::Array::New(isolate, target, writePosition);
|
|
161
|
+
done:
|
|
162
|
+
napi_value returnValue;
|
|
163
|
+
memcpy(&returnValue, &v8ReturnValue, sizeof(napi_value));
|
|
164
|
+
return returnValue;
|
|
165
|
+
/*#else
|
|
166
|
+
v8::Local<v8::Array> array = v8::Array::New(isolate, writePosition);
|
|
167
|
+
v8::Local<v8::Context> context = v8::Isolate::GetCurrentContext();
|
|
160
168
|
for (int i = 0; i < writePosition; i++) {
|
|
161
169
|
array->Set(context, i, target[i]);
|
|
162
170
|
}
|
|
163
|
-
return array
|
|
164
|
-
|
|
171
|
+
return array;*/
|
|
172
|
+
//#endif
|
|
165
173
|
}
|
|
166
174
|
};
|
|
167
|
-
|
|
175
|
+
|
|
176
|
+
void setupTokenTable(Env env) {
|
|
168
177
|
for (int i = 0; i < 256; i++) {
|
|
169
178
|
tokenTable[i] = nullptr;
|
|
170
179
|
}
|
|
@@ -185,18 +194,18 @@ void setupTokenTable() {
|
|
|
185
194
|
// fixext 16
|
|
186
195
|
tokenTable[0xd8] = (token_handler) 17;
|
|
187
196
|
// bin 8
|
|
188
|
-
tokenTable[0xc4] = ([](uint8_t* source, int position, int size) -> int {
|
|
197
|
+
tokenTable[0xc4] = ([](Env env, uint8_t* source, int position, int size) -> int {
|
|
189
198
|
if (position >= size) {
|
|
190
|
-
|
|
199
|
+
TypeError::New(env, "Unexpected end of buffer").ThrowAsJavaScriptException();
|
|
191
200
|
return size;
|
|
192
201
|
}
|
|
193
202
|
int length = source[position++];
|
|
194
203
|
return position + length;
|
|
195
204
|
});
|
|
196
205
|
// bin 16
|
|
197
|
-
tokenTable[0xc5] = ([](uint8_t* source, int position, int size) -> int {
|
|
206
|
+
tokenTable[0xc5] = ([](Env env, uint8_t* source, int position, int size) -> int {
|
|
198
207
|
if (position + 2 > size) {
|
|
199
|
-
|
|
208
|
+
TypeError::New(env, "Unexpected end of buffer").ThrowAsJavaScriptException();
|
|
200
209
|
return size;
|
|
201
210
|
}
|
|
202
211
|
int length = source[position++] << 8;
|
|
@@ -204,7 +213,7 @@ void setupTokenTable() {
|
|
|
204
213
|
return position + length;
|
|
205
214
|
});
|
|
206
215
|
// bin 32
|
|
207
|
-
tokenTable[0xc6] = ([](uint8_t* source, int position, int size) -> int {
|
|
216
|
+
tokenTable[0xc6] = ([](Env env, uint8_t* source, int position, int size) -> int {
|
|
208
217
|
if (position + 4 > size)
|
|
209
218
|
return -1;
|
|
210
219
|
int length = source[position++] << 24;
|
|
@@ -214,7 +223,7 @@ void setupTokenTable() {
|
|
|
214
223
|
return position + length;
|
|
215
224
|
});
|
|
216
225
|
// ext 8
|
|
217
|
-
tokenTable[0xc7] = ([](uint8_t* source, int position, int size) -> int {
|
|
226
|
+
tokenTable[0xc7] = ([](Env env, uint8_t* source, int position, int size) -> int {
|
|
218
227
|
if (position >= size)
|
|
219
228
|
return -1;
|
|
220
229
|
int length = source[position++];
|
|
@@ -222,7 +231,7 @@ void setupTokenTable() {
|
|
|
222
231
|
return position + length;
|
|
223
232
|
});
|
|
224
233
|
// ext 16
|
|
225
|
-
tokenTable[0xc8] = ([](uint8_t* source, int position, int size) -> int {
|
|
234
|
+
tokenTable[0xc8] = ([](Env env, uint8_t* source, int position, int size) -> int {
|
|
226
235
|
if (position + 2 > size)
|
|
227
236
|
return -1;
|
|
228
237
|
int length = source[position++] << 8;
|
|
@@ -231,7 +240,7 @@ void setupTokenTable() {
|
|
|
231
240
|
return position + length;
|
|
232
241
|
});
|
|
233
242
|
// ext 32
|
|
234
|
-
tokenTable[0xc9] = ([](uint8_t* source, int position, int size) -> int {
|
|
243
|
+
tokenTable[0xc9] = ([](Env env, uint8_t* source, int position, int size) -> int {
|
|
235
244
|
if (position + 4 > size)
|
|
236
245
|
return -1;
|
|
237
246
|
int length = source[position++] << 24;
|
|
@@ -245,25 +254,38 @@ void setupTokenTable() {
|
|
|
245
254
|
|
|
246
255
|
static thread_local Extractor* extractor;
|
|
247
256
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
int position =
|
|
251
|
-
int size =
|
|
252
|
-
if (info[2]
|
|
253
|
-
|
|
254
|
-
|
|
257
|
+
napi_value extractStrings(const CallbackInfo& info) {
|
|
258
|
+
Env env = info.Env();
|
|
259
|
+
int position = info[0].As<Number>();
|
|
260
|
+
int size = info[1].As<Number>();
|
|
261
|
+
if (info[2].IsTypedArray()) {
|
|
262
|
+
TypedArray typedArray = info[2].As<TypedArray>();
|
|
263
|
+
uint8_t* source = ((uint8_t*) typedArray.ArrayBuffer().Data()) + typedArray.ByteOffset();
|
|
264
|
+
return extractor->extractStrings(env, position, size, source);
|
|
255
265
|
}
|
|
266
|
+
return env.Undefined();
|
|
256
267
|
}
|
|
257
268
|
|
|
258
|
-
|
|
259
|
-
|
|
269
|
+
napi_value isOneByte(const CallbackInfo& info) {
|
|
270
|
+
Env env = info.Env();
|
|
271
|
+
size_t length;
|
|
272
|
+
napi_get_value_string_latin1(env, info[0], nullptr, 0, &length);
|
|
273
|
+
|
|
274
|
+
return Boolean::New(env, length == 1);
|
|
260
275
|
}
|
|
261
276
|
|
|
262
|
-
|
|
277
|
+
Object Init(Env env, Object exports) {
|
|
263
278
|
extractor = new Extractor(); // create our thread-local extractor
|
|
264
|
-
setupTokenTable();
|
|
265
|
-
|
|
266
|
-
|
|
279
|
+
setupTokenTable(env);
|
|
280
|
+
exports.Set(
|
|
281
|
+
String::New(env, "extractStrings"),
|
|
282
|
+
Function::New(env, extractStrings)
|
|
283
|
+
);
|
|
284
|
+
exports.Set(
|
|
285
|
+
String::New(env, "isOneByte"),
|
|
286
|
+
Function::New(env, isOneByte)
|
|
287
|
+
);
|
|
288
|
+
return exports;
|
|
267
289
|
}
|
|
268
290
|
|
|
269
|
-
|
|
291
|
+
NODE_API_MODULE(extractor, Init)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|