cline 1.0.1 → 1.0.2
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/bin/cline +0 -0
- package/bin/cline-darwin-amd64 +0 -0
- package/bin/cline-darwin-arm64 +0 -0
- package/bin/cline-host +0 -0
- package/bin/cline-host-darwin-amd64 +0 -0
- package/bin/cline-host-darwin-arm64 +0 -0
- package/bin/cline-host-linux-amd64 +0 -0
- package/bin/cline-host-linux-arm64 +0 -0
- package/bin/cline-linux-amd64 +0 -0
- package/bin/cline-linux-arm64 +0 -0
- package/cline-core.js +24143 -16610
- package/extension/package.json +12 -4
- package/node_modules/b4a/LICENSE +201 -0
- package/node_modules/b4a/README.md +153 -0
- package/node_modules/b4a/browser.js +563 -0
- package/node_modules/b4a/index.js +188 -0
- package/node_modules/b4a/lib/ascii.js +31 -0
- package/node_modules/b4a/lib/base64.js +65 -0
- package/node_modules/b4a/lib/hex.js +51 -0
- package/node_modules/b4a/lib/utf16le.js +40 -0
- package/node_modules/b4a/lib/utf8.js +141 -0
- package/node_modules/b4a/package.json +49 -0
- package/node_modules/b4a/react-native.js +5 -0
- package/node_modules/bare-events/LICENSE +201 -0
- package/node_modules/bare-events/README.md +25 -0
- package/node_modules/bare-events/global.d.ts +15 -0
- package/node_modules/bare-events/global.js +5 -0
- package/node_modules/bare-events/index.d.ts +94 -0
- package/node_modules/bare-events/index.js +355 -0
- package/node_modules/bare-events/lib/errors.js +32 -0
- package/node_modules/bare-events/package.json +61 -0
- package/node_modules/bare-events/web.d.ts +79 -0
- package/node_modules/bare-events/web.js +347 -0
- package/node_modules/bare-fs/CMakeLists.txt +13 -0
- package/node_modules/bare-fs/LICENSE +201 -0
- package/node_modules/bare-fs/README.md +29 -0
- package/node_modules/bare-fs/binding.c +2238 -0
- package/node_modules/bare-fs/binding.js +1 -0
- package/node_modules/bare-fs/index.d.ts +1115 -0
- package/node_modules/bare-fs/index.js +2330 -0
- package/node_modules/bare-fs/lib/constants.d.ts +49 -0
- package/node_modules/bare-fs/lib/constants.js +49 -0
- package/node_modules/bare-fs/lib/errors.d.ts +11 -0
- package/node_modules/bare-fs/lib/errors.js +55 -0
- package/node_modules/bare-fs/package.json +71 -0
- package/node_modules/bare-fs/prebuilds/android-arm/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/android-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/android-ia32/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/android-x64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/darwin-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/darwin-x64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/ios-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/ios-arm64-simulator/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/ios-x64-simulator/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/linux-x64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/win32-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/win32-x64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/promises.d.ts +282 -0
- package/node_modules/bare-fs/promises.js +90 -0
- package/node_modules/bare-os/CMakeLists.txt +13 -0
- package/node_modules/bare-os/LICENSE +201 -0
- package/node_modules/bare-os/README.md +11 -0
- package/node_modules/bare-os/binding.c +1119 -0
- package/node_modules/bare-os/binding.js +1 -0
- package/node_modules/bare-os/index.d.ts +109 -0
- package/node_modules/bare-os/index.js +99 -0
- package/node_modules/bare-os/lib/constants.js +6 -0
- package/node_modules/bare-os/lib/errors.js +22 -0
- package/node_modules/bare-os/package.json +46 -0
- package/node_modules/bare-os/prebuilds/android-arm/bare-os.bare +0 -0
- package/node_modules/bare-os/prebuilds/android-arm64/bare-os.bare +0 -0
- package/node_modules/bare-os/prebuilds/android-ia32/bare-os.bare +0 -0
- package/node_modules/bare-os/prebuilds/android-x64/bare-os.bare +0 -0
- package/node_modules/bare-os/prebuilds/darwin-arm64/bare-os.bare +0 -0
- package/node_modules/bare-os/prebuilds/darwin-x64/bare-os.bare +0 -0
- package/node_modules/bare-os/prebuilds/ios-arm64/bare-os.bare +0 -0
- package/node_modules/bare-os/prebuilds/ios-arm64-simulator/bare-os.bare +0 -0
- package/node_modules/bare-os/prebuilds/ios-x64-simulator/bare-os.bare +0 -0
- package/node_modules/bare-os/prebuilds/linux-arm64/bare-os.bare +0 -0
- package/node_modules/bare-os/prebuilds/linux-x64/bare-os.bare +0 -0
- package/node_modules/bare-os/prebuilds/win32-arm64/bare-os.bare +0 -0
- package/node_modules/bare-os/prebuilds/win32-x64/bare-os.bare +0 -0
- package/node_modules/bare-path/LICENSE +201 -0
- package/node_modules/bare-path/NOTICE +28 -0
- package/node_modules/bare-path/README.md +19 -0
- package/node_modules/bare-path/index.js +11 -0
- package/node_modules/bare-path/lib/constants.js +11 -0
- package/node_modules/bare-path/lib/posix.js +242 -0
- package/node_modules/bare-path/lib/shared.js +67 -0
- package/node_modules/bare-path/lib/win32.js +513 -0
- package/node_modules/bare-path/package.json +36 -0
- package/node_modules/bare-stream/LICENSE +201 -0
- package/node_modules/bare-stream/README.md +15 -0
- package/node_modules/bare-stream/global.js +8 -0
- package/node_modules/bare-stream/index.d.ts +237 -0
- package/node_modules/bare-stream/index.js +355 -0
- package/node_modules/bare-stream/package.json +61 -0
- package/node_modules/bare-stream/promises.js +3 -0
- package/node_modules/bare-stream/web.d.ts +73 -0
- package/node_modules/bare-stream/web.js +229 -0
- package/node_modules/bare-url/CMakeLists.txt +27 -0
- package/node_modules/bare-url/LICENSE +201 -0
- package/node_modules/bare-url/README.md +19 -0
- package/node_modules/bare-url/binding.c +188 -0
- package/node_modules/bare-url/binding.js +1 -0
- package/node_modules/bare-url/global.d.ts +12 -0
- package/node_modules/bare-url/global.js +2 -0
- package/node_modules/bare-url/index.d.ts +39 -0
- package/node_modules/bare-url/index.js +450 -0
- package/node_modules/bare-url/lib/errors.d.ts +8 -0
- package/node_modules/bare-url/lib/errors.js +38 -0
- package/node_modules/bare-url/lib/url-search-params.d.ts +21 -0
- package/node_modules/bare-url/lib/url-search-params.js +176 -0
- package/node_modules/bare-url/package.json +51 -0
- package/node_modules/bare-url/prebuilds/android-arm/bare-url.bare +0 -0
- package/node_modules/bare-url/prebuilds/android-arm64/bare-url.bare +0 -0
- package/node_modules/bare-url/prebuilds/android-ia32/bare-url.bare +0 -0
- package/node_modules/bare-url/prebuilds/android-x64/bare-url.bare +0 -0
- package/node_modules/bare-url/prebuilds/darwin-arm64/bare-url.bare +0 -0
- package/node_modules/bare-url/prebuilds/darwin-x64/bare-url.bare +0 -0
- package/node_modules/bare-url/prebuilds/ios-arm64/bare-url.bare +0 -0
- package/node_modules/bare-url/prebuilds/ios-arm64-simulator/bare-url.bare +0 -0
- package/node_modules/bare-url/prebuilds/ios-x64-simulator/bare-url.bare +0 -0
- package/node_modules/bare-url/prebuilds/linux-arm64/bare-url.bare +0 -0
- package/node_modules/bare-url/prebuilds/linux-x64/bare-url.bare +0 -0
- package/node_modules/bare-url/prebuilds/win32-arm64/bare-url.bare +0 -0
- package/node_modules/bare-url/prebuilds/win32-x64/bare-url.bare +0 -0
- package/node_modules/better-sqlite3/deps/download.sh +1 -1
- package/node_modules/better-sqlite3/deps/sqlite3/sqlite3.c +122 -81
- package/node_modules/better-sqlite3/deps/sqlite3/sqlite3.h +45 -45
- package/node_modules/better-sqlite3/lib/database.js +1 -1
- package/node_modules/better-sqlite3/package.json +4 -7
- package/node_modules/better-sqlite3/src/addon.cpp +47 -0
- package/node_modules/better-sqlite3/src/better_sqlite3.cpp +44 -2164
- package/node_modules/better-sqlite3/src/objects/backup.cpp +120 -0
- package/node_modules/better-sqlite3/src/objects/backup.hpp +36 -0
- package/node_modules/better-sqlite3/src/objects/database.cpp +417 -0
- package/node_modules/better-sqlite3/src/objects/database.hpp +103 -0
- package/node_modules/better-sqlite3/src/objects/statement-iterator.cpp +113 -0
- package/node_modules/better-sqlite3/src/objects/statement-iterator.hpp +50 -0
- package/node_modules/better-sqlite3/src/objects/statement.cpp +383 -0
- package/node_modules/better-sqlite3/src/objects/statement.hpp +58 -0
- package/node_modules/better-sqlite3/src/util/bind-map.cpp +73 -0
- package/node_modules/better-sqlite3/src/util/binder.cpp +193 -0
- package/node_modules/better-sqlite3/src/util/constants.cpp +172 -0
- package/node_modules/better-sqlite3/src/util/custom-aggregate.cpp +121 -0
- package/node_modules/better-sqlite3/src/util/custom-function.cpp +59 -0
- package/node_modules/better-sqlite3/src/util/custom-table.cpp +409 -0
- package/node_modules/better-sqlite3/src/util/data-converter.cpp +17 -0
- package/node_modules/better-sqlite3/src/util/data.cpp +194 -0
- package/node_modules/better-sqlite3/src/util/helpers.cpp +109 -0
- package/node_modules/better-sqlite3/src/util/macros.cpp +63 -0
- package/node_modules/better-sqlite3/src/util/query-macros.cpp +71 -0
- package/node_modules/better-sqlite3/src/util/row-builder.cpp +49 -0
- package/node_modules/events-universal/LICENSE +201 -0
- package/node_modules/events-universal/README.md +17 -0
- package/node_modules/events-universal/bare.js +1 -0
- package/node_modules/events-universal/default.js +1 -0
- package/node_modules/events-universal/index.js +1 -0
- package/node_modules/events-universal/package.json +39 -0
- package/node_modules/events-universal/react-native.js +1 -0
- package/node_modules/{fs-constants → fast-fifo}/LICENSE +1 -1
- package/node_modules/fast-fifo/README.md +78 -0
- package/node_modules/fast-fifo/fixed-size.js +39 -0
- package/node_modules/fast-fifo/index.js +48 -0
- package/node_modules/fast-fifo/package.json +28 -0
- package/node_modules/{base64-js → streamx}/LICENSE +1 -1
- package/node_modules/streamx/README.md +489 -0
- package/node_modules/streamx/index.js +1184 -0
- package/node_modules/streamx/package.json +34 -0
- package/node_modules/tar-fs/README.md +23 -34
- package/node_modules/tar-fs/index.js +211 -184
- package/node_modules/tar-fs/package.json +27 -7
- package/node_modules/tar-stream/README.md +34 -19
- package/node_modules/tar-stream/constants.js +14 -0
- package/node_modules/tar-stream/extract.js +341 -192
- package/node_modules/tar-stream/headers.js +201 -175
- package/node_modules/tar-stream/pack.js +226 -194
- package/node_modules/tar-stream/package.json +23 -46
- package/node_modules/text-decoder/LICENSE +201 -0
- package/node_modules/text-decoder/README.md +36 -0
- package/node_modules/text-decoder/index.js +64 -0
- package/node_modules/text-decoder/lib/browser-decoder.js +17 -0
- package/node_modules/text-decoder/lib/pass-through-decoder.js +19 -0
- package/node_modules/text-decoder/lib/utf8-decoder.js +104 -0
- package/node_modules/text-decoder/package.json +38 -0
- package/package.json +1 -1
- package/proto/cline/account.proto +10 -8
- package/proto/cline/browser.proto +3 -1
- package/proto/cline/checkpoints.proto +5 -3
- package/proto/cline/commands.proto +4 -2
- package/proto/cline/common.proto +5 -7
- package/proto/cline/dictation.proto +3 -1
- package/proto/cline/file.proto +36 -34
- package/proto/cline/hooks.proto +3 -2
- package/proto/cline/mcp.proto +6 -4
- package/proto/cline/models.proto +189 -19
- package/proto/cline/oca_account.proto +6 -7
- package/proto/cline/slash.proto +3 -1
- package/proto/cline/state.proto +144 -292
- package/proto/cline/task.proto +4 -2
- package/proto/cline/ui.proto +25 -24
- package/proto/cline/web.proto +3 -1
- package/proto/descriptor_set.pb +0 -0
- package/proto/host/diff.proto +5 -4
- package/proto/host/env.proto +8 -7
- package/proto/host/testing.proto +3 -3
- package/proto/host/window.proto +2 -2
- package/proto/host/workspace.proto +13 -12
- package/node_modules/base64-js/README.md +0 -34
- package/node_modules/base64-js/base64js.min.js +0 -1
- package/node_modules/base64-js/index.d.ts +0 -3
- package/node_modules/base64-js/index.js +0 -150
- package/node_modules/base64-js/package.json +0 -47
- package/node_modules/better-sqlite3/src/better_sqlite3.hpp +0 -1036
- package/node_modules/bl/.travis.yml +0 -17
- package/node_modules/bl/BufferList.js +0 -396
- package/node_modules/bl/LICENSE.md +0 -13
- package/node_modules/bl/README.md +0 -247
- package/node_modules/bl/bl.js +0 -84
- package/node_modules/bl/package.json +0 -37
- package/node_modules/bl/test/convert.js +0 -21
- package/node_modules/bl/test/indexOf.js +0 -492
- package/node_modules/bl/test/isBufferList.js +0 -32
- package/node_modules/bl/test/test.js +0 -869
- package/node_modules/buffer/AUTHORS.md +0 -70
- package/node_modules/buffer/LICENSE +0 -21
- package/node_modules/buffer/README.md +0 -410
- package/node_modules/buffer/index.d.ts +0 -186
- package/node_modules/buffer/index.js +0 -1817
- package/node_modules/buffer/package.json +0 -96
- package/node_modules/chownr/LICENSE +0 -15
- package/node_modules/chownr/README.md +0 -3
- package/node_modules/chownr/chownr.js +0 -167
- package/node_modules/chownr/package.json +0 -29
- package/node_modules/fs-constants/README.md +0 -26
- package/node_modules/fs-constants/browser.js +0 -1
- package/node_modules/fs-constants/index.js +0 -1
- package/node_modules/fs-constants/package.json +0 -19
- package/node_modules/ieee754/LICENSE +0 -11
- package/node_modules/ieee754/README.md +0 -51
- package/node_modules/ieee754/index.d.ts +0 -10
- package/node_modules/ieee754/index.js +0 -85
- package/node_modules/ieee754/package.json +0 -52
- package/node_modules/inherits/LICENSE +0 -16
- package/node_modules/inherits/README.md +0 -42
- package/node_modules/inherits/inherits.js +0 -9
- package/node_modules/inherits/inherits_browser.js +0 -27
- package/node_modules/inherits/package.json +0 -29
- package/node_modules/readable-stream/CONTRIBUTING.md +0 -38
- package/node_modules/readable-stream/GOVERNANCE.md +0 -136
- package/node_modules/readable-stream/LICENSE +0 -47
- package/node_modules/readable-stream/README.md +0 -106
- package/node_modules/readable-stream/errors-browser.js +0 -127
- package/node_modules/readable-stream/errors.js +0 -116
- package/node_modules/readable-stream/experimentalWarning.js +0 -17
- package/node_modules/readable-stream/lib/_stream_duplex.js +0 -126
- package/node_modules/readable-stream/lib/_stream_passthrough.js +0 -37
- package/node_modules/readable-stream/lib/_stream_readable.js +0 -1027
- package/node_modules/readable-stream/lib/_stream_transform.js +0 -190
- package/node_modules/readable-stream/lib/_stream_writable.js +0 -641
- package/node_modules/readable-stream/lib/internal/streams/async_iterator.js +0 -180
- package/node_modules/readable-stream/lib/internal/streams/buffer_list.js +0 -183
- package/node_modules/readable-stream/lib/internal/streams/destroy.js +0 -96
- package/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +0 -86
- package/node_modules/readable-stream/lib/internal/streams/from-browser.js +0 -3
- package/node_modules/readable-stream/lib/internal/streams/from.js +0 -52
- package/node_modules/readable-stream/lib/internal/streams/pipeline.js +0 -86
- package/node_modules/readable-stream/lib/internal/streams/state.js +0 -22
- package/node_modules/readable-stream/lib/internal/streams/stream-browser.js +0 -1
- package/node_modules/readable-stream/lib/internal/streams/stream.js +0 -1
- package/node_modules/readable-stream/package.json +0 -68
- package/node_modules/readable-stream/readable-browser.js +0 -9
- package/node_modules/readable-stream/readable.js +0 -16
- package/node_modules/string_decoder/LICENSE +0 -48
- package/node_modules/string_decoder/README.md +0 -47
- package/node_modules/string_decoder/lib/string_decoder.js +0 -296
- package/node_modules/string_decoder/package.json +0 -34
- package/node_modules/tar-fs/.travis.yml +0 -6
- package/node_modules/tar-fs/test/fixtures/a/hello.txt +0 -1
- package/node_modules/tar-fs/test/fixtures/b/a/test.txt +0 -1
- package/node_modules/tar-fs/test/fixtures/d/file1 +0 -0
- package/node_modules/tar-fs/test/fixtures/d/file2 +0 -0
- package/node_modules/tar-fs/test/fixtures/d/sub-dir/file5 +0 -0
- package/node_modules/tar-fs/test/fixtures/d/sub-files/file3 +0 -0
- package/node_modules/tar-fs/test/fixtures/d/sub-files/file4 +0 -0
- package/node_modules/tar-fs/test/fixtures/e/directory/.ignore +0 -0
- package/node_modules/tar-fs/test/fixtures/e/file +0 -0
- package/node_modules/tar-fs/test/fixtures/invalid.tar +0 -0
- package/node_modules/tar-fs/test/index.js +0 -346
- package/node_modules/tar-stream/sandbox.js +0 -11
- package/node_modules/util-deprecate/History.md +0 -16
- package/node_modules/util-deprecate/LICENSE +0 -24
- package/node_modules/util-deprecate/README.md +0 -53
- package/node_modules/util-deprecate/browser.js +0 -67
- package/node_modules/util-deprecate/node.js +0 -6
- package/node_modules/util-deprecate/package.json +0 -27
- package/test-startup.sh +0 -14
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
class Binder {
|
|
2
|
+
public:
|
|
3
|
+
|
|
4
|
+
explicit Binder(sqlite3_stmt* _handle) {
|
|
5
|
+
handle = _handle;
|
|
6
|
+
param_count = sqlite3_bind_parameter_count(_handle);
|
|
7
|
+
anon_index = 0;
|
|
8
|
+
success = true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
bool Bind(NODE_ARGUMENTS info, int argc, Statement* stmt) {
|
|
12
|
+
assert(anon_index == 0);
|
|
13
|
+
Result result = BindArgs(info, argc, stmt);
|
|
14
|
+
if (success && result.count != param_count) {
|
|
15
|
+
if (result.count < param_count) {
|
|
16
|
+
if (!result.bound_object && stmt->GetBindMap(OnlyIsolate)->GetSize()) {
|
|
17
|
+
Fail(ThrowTypeError, "Missing named parameters");
|
|
18
|
+
} else {
|
|
19
|
+
Fail(ThrowRangeError, "Too few parameter values were provided");
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
Fail(ThrowRangeError, "Too many parameter values were provided");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return success;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private:
|
|
29
|
+
|
|
30
|
+
struct Result {
|
|
31
|
+
int count;
|
|
32
|
+
bool bound_object;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
static bool IsPlainObject(v8::Isolate* isolate, v8::Local<v8::Object> obj) {
|
|
36
|
+
v8::Local<v8::Value> proto = obj->GetPrototype();
|
|
37
|
+
v8::Local<v8::Context> ctx = obj->GetCreationContext().ToLocalChecked();
|
|
38
|
+
ctx->Enter();
|
|
39
|
+
v8::Local<v8::Value> baseProto = v8::Object::New(isolate)->GetPrototype();
|
|
40
|
+
ctx->Exit();
|
|
41
|
+
return proto->StrictEquals(baseProto) || proto->StrictEquals(v8::Null(isolate));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void Fail(void (*Throw)(const char* _), const char* message) {
|
|
45
|
+
assert(success == true);
|
|
46
|
+
assert((Throw == NULL) == (message == NULL));
|
|
47
|
+
assert(Throw == ThrowError || Throw == ThrowTypeError || Throw == ThrowRangeError || Throw == NULL);
|
|
48
|
+
if (Throw) Throw(message);
|
|
49
|
+
success = false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
int NextAnonIndex() {
|
|
53
|
+
while (sqlite3_bind_parameter_name(handle, ++anon_index) != NULL) {}
|
|
54
|
+
return anon_index;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Binds the value at the given index or throws an appropriate error.
|
|
58
|
+
void BindValue(v8::Isolate* isolate, v8::Local<v8::Value> value, int index) {
|
|
59
|
+
int status = Data::BindValueFromJS(isolate, handle, index, value);
|
|
60
|
+
if (status != SQLITE_OK) {
|
|
61
|
+
switch (status) {
|
|
62
|
+
case -1:
|
|
63
|
+
return Fail(ThrowTypeError, "SQLite3 can only bind numbers, strings, bigints, buffers, and null");
|
|
64
|
+
case SQLITE_TOOBIG:
|
|
65
|
+
return Fail(ThrowRangeError, "The bound string, buffer, or bigint is too big");
|
|
66
|
+
case SQLITE_RANGE:
|
|
67
|
+
return Fail(ThrowRangeError, "Too many parameter values were provided");
|
|
68
|
+
case SQLITE_NOMEM:
|
|
69
|
+
return Fail(ThrowError, "Out of memory");
|
|
70
|
+
default:
|
|
71
|
+
return Fail(ThrowError, "An unexpected error occured while trying to bind parameters");
|
|
72
|
+
}
|
|
73
|
+
assert(false);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Binds each value in the array or throws an appropriate error.
|
|
78
|
+
// The number of successfully bound parameters is returned.
|
|
79
|
+
int BindArray(v8::Isolate* isolate, v8::Local<v8::Array> arr) {
|
|
80
|
+
UseContext;
|
|
81
|
+
uint32_t length = arr->Length();
|
|
82
|
+
if (length > INT_MAX) {
|
|
83
|
+
Fail(ThrowRangeError, "Too many parameter values were provided");
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
int len = static_cast<int>(length);
|
|
87
|
+
for (int i = 0; i < len; ++i) {
|
|
88
|
+
v8::MaybeLocal<v8::Value> maybeValue = arr->Get(ctx, i);
|
|
89
|
+
if (maybeValue.IsEmpty()) {
|
|
90
|
+
Fail(NULL, NULL);
|
|
91
|
+
return i;
|
|
92
|
+
}
|
|
93
|
+
BindValue(isolate, maybeValue.ToLocalChecked(), NextAnonIndex());
|
|
94
|
+
if (!success) {
|
|
95
|
+
return i;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return len;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Binds all named parameters using the values found in the given object.
|
|
102
|
+
// The number of successfully bound parameters is returned.
|
|
103
|
+
// If a named parameter is missing from the object, an error is thrown.
|
|
104
|
+
// This should only be invoked once per instance.
|
|
105
|
+
int BindObject(v8::Isolate* isolate, v8::Local<v8::Object> obj, Statement* stmt) {
|
|
106
|
+
UseContext;
|
|
107
|
+
BindMap* bind_map = stmt->GetBindMap(isolate);
|
|
108
|
+
BindMap::Pair* pairs = bind_map->GetPairs();
|
|
109
|
+
int len = bind_map->GetSize();
|
|
110
|
+
|
|
111
|
+
for (int i = 0; i < len; ++i) {
|
|
112
|
+
v8::Local<v8::String> key = pairs[i].GetName(isolate);
|
|
113
|
+
|
|
114
|
+
// Check if the named parameter was provided.
|
|
115
|
+
v8::Maybe<bool> has_property = obj->HasOwnProperty(ctx, key);
|
|
116
|
+
if (has_property.IsNothing()) {
|
|
117
|
+
Fail(NULL, NULL);
|
|
118
|
+
return i;
|
|
119
|
+
}
|
|
120
|
+
if (!has_property.FromJust()) {
|
|
121
|
+
v8::String::Utf8Value param_name(isolate, key);
|
|
122
|
+
Fail(ThrowRangeError, (std::string("Missing named parameter \"") + *param_name + "\"").c_str());
|
|
123
|
+
return i;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Get the current property value.
|
|
127
|
+
v8::MaybeLocal<v8::Value> maybeValue = obj->Get(ctx, key);
|
|
128
|
+
if (maybeValue.IsEmpty()) {
|
|
129
|
+
Fail(NULL, NULL);
|
|
130
|
+
return i;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
BindValue(isolate, maybeValue.ToLocalChecked(), pairs[i].GetIndex());
|
|
134
|
+
if (!success) {
|
|
135
|
+
return i;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return len;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Binds all parameters using the values found in the arguments object.
|
|
143
|
+
// Anonymous parameter values can be directly in the arguments object or in an Array.
|
|
144
|
+
// Named parameter values can be provided in a plain Object argument.
|
|
145
|
+
// Only one plain Object argument may be provided.
|
|
146
|
+
// If an error occurs, an appropriate error is thrown.
|
|
147
|
+
// The return value is a struct indicating how many parameters were successfully bound
|
|
148
|
+
// and whether or not it tried to bind an object.
|
|
149
|
+
Result BindArgs(NODE_ARGUMENTS info, int argc, Statement* stmt) {
|
|
150
|
+
UseIsolate;
|
|
151
|
+
int count = 0;
|
|
152
|
+
bool bound_object = false;
|
|
153
|
+
|
|
154
|
+
for (int i = 0; i < argc; ++i) {
|
|
155
|
+
v8::Local<v8::Value> arg = info[i];
|
|
156
|
+
|
|
157
|
+
if (arg->IsArray()) {
|
|
158
|
+
count += BindArray(isolate, arg.As<v8::Array>());
|
|
159
|
+
if (!success) break;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (arg->IsObject() && !node::Buffer::HasInstance(arg)) {
|
|
164
|
+
v8::Local<v8::Object> obj = arg.As<v8::Object>();
|
|
165
|
+
if (IsPlainObject(isolate, obj)) {
|
|
166
|
+
if (bound_object) {
|
|
167
|
+
Fail(ThrowTypeError, "You cannot specify named parameters in two different objects");
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
bound_object = true;
|
|
171
|
+
|
|
172
|
+
count += BindObject(isolate, obj, stmt);
|
|
173
|
+
if (!success) break;
|
|
174
|
+
continue;
|
|
175
|
+
} else if (stmt->GetBindMap(isolate)->GetSize()) {
|
|
176
|
+
Fail(ThrowTypeError, "Named parameters can only be passed within plain objects");
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
BindValue(isolate, arg, NextAnonIndex());
|
|
182
|
+
if (!success) break;
|
|
183
|
+
count += 1;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return { count, bound_object };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
sqlite3_stmt* handle;
|
|
190
|
+
int param_count;
|
|
191
|
+
int anon_index; // This value should only be used by NextAnonIndex()
|
|
192
|
+
bool success; // This value should only be set by Fail()
|
|
193
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
class CS {
|
|
2
|
+
public:
|
|
3
|
+
|
|
4
|
+
v8::Local<v8::String> Code(v8::Isolate* isolate, int code) {
|
|
5
|
+
auto element = codes.find(code);
|
|
6
|
+
if (element != codes.end()) return element->second.Get(isolate);
|
|
7
|
+
return StringFromUtf8(isolate, (std::string("UNKNOWN_SQLITE_ERROR_") + std::to_string(code)).c_str(), -1);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
explicit CS(v8::Isolate* isolate) {
|
|
11
|
+
SetString(isolate, database, "database");
|
|
12
|
+
SetString(isolate, reader, "reader");
|
|
13
|
+
SetString(isolate, source, "source");
|
|
14
|
+
SetString(isolate, memory, "memory");
|
|
15
|
+
SetString(isolate, readonly, "readonly");
|
|
16
|
+
SetString(isolate, name, "name");
|
|
17
|
+
SetString(isolate, next, "next");
|
|
18
|
+
SetString(isolate, length, "length");
|
|
19
|
+
SetString(isolate, done, "done");
|
|
20
|
+
SetString(isolate, value, "value");
|
|
21
|
+
SetString(isolate, changes, "changes");
|
|
22
|
+
SetString(isolate, lastInsertRowid, "lastInsertRowid");
|
|
23
|
+
SetString(isolate, statement, "statement");
|
|
24
|
+
SetString(isolate, column, "column");
|
|
25
|
+
SetString(isolate, table, "table");
|
|
26
|
+
SetString(isolate, type, "type");
|
|
27
|
+
SetString(isolate, totalPages, "totalPages");
|
|
28
|
+
SetString(isolate, remainingPages, "remainingPages");
|
|
29
|
+
|
|
30
|
+
SetCode(isolate, SQLITE_OK, "SQLITE_OK");
|
|
31
|
+
SetCode(isolate, SQLITE_ERROR, "SQLITE_ERROR");
|
|
32
|
+
SetCode(isolate, SQLITE_INTERNAL, "SQLITE_INTERNAL");
|
|
33
|
+
SetCode(isolate, SQLITE_PERM, "SQLITE_PERM");
|
|
34
|
+
SetCode(isolate, SQLITE_ABORT, "SQLITE_ABORT");
|
|
35
|
+
SetCode(isolate, SQLITE_BUSY, "SQLITE_BUSY");
|
|
36
|
+
SetCode(isolate, SQLITE_LOCKED, "SQLITE_LOCKED");
|
|
37
|
+
SetCode(isolate, SQLITE_NOMEM, "SQLITE_NOMEM");
|
|
38
|
+
SetCode(isolate, SQLITE_READONLY, "SQLITE_READONLY");
|
|
39
|
+
SetCode(isolate, SQLITE_INTERRUPT, "SQLITE_INTERRUPT");
|
|
40
|
+
SetCode(isolate, SQLITE_IOERR, "SQLITE_IOERR");
|
|
41
|
+
SetCode(isolate, SQLITE_CORRUPT, "SQLITE_CORRUPT");
|
|
42
|
+
SetCode(isolate, SQLITE_NOTFOUND, "SQLITE_NOTFOUND");
|
|
43
|
+
SetCode(isolate, SQLITE_FULL, "SQLITE_FULL");
|
|
44
|
+
SetCode(isolate, SQLITE_CANTOPEN, "SQLITE_CANTOPEN");
|
|
45
|
+
SetCode(isolate, SQLITE_PROTOCOL, "SQLITE_PROTOCOL");
|
|
46
|
+
SetCode(isolate, SQLITE_EMPTY, "SQLITE_EMPTY");
|
|
47
|
+
SetCode(isolate, SQLITE_SCHEMA, "SQLITE_SCHEMA");
|
|
48
|
+
SetCode(isolate, SQLITE_TOOBIG, "SQLITE_TOOBIG");
|
|
49
|
+
SetCode(isolate, SQLITE_CONSTRAINT, "SQLITE_CONSTRAINT");
|
|
50
|
+
SetCode(isolate, SQLITE_MISMATCH, "SQLITE_MISMATCH");
|
|
51
|
+
SetCode(isolate, SQLITE_MISUSE, "SQLITE_MISUSE");
|
|
52
|
+
SetCode(isolate, SQLITE_NOLFS, "SQLITE_NOLFS");
|
|
53
|
+
SetCode(isolate, SQLITE_AUTH, "SQLITE_AUTH");
|
|
54
|
+
SetCode(isolate, SQLITE_FORMAT, "SQLITE_FORMAT");
|
|
55
|
+
SetCode(isolate, SQLITE_RANGE, "SQLITE_RANGE");
|
|
56
|
+
SetCode(isolate, SQLITE_NOTADB, "SQLITE_NOTADB");
|
|
57
|
+
SetCode(isolate, SQLITE_NOTICE, "SQLITE_NOTICE");
|
|
58
|
+
SetCode(isolate, SQLITE_WARNING, "SQLITE_WARNING");
|
|
59
|
+
SetCode(isolate, SQLITE_ROW, "SQLITE_ROW");
|
|
60
|
+
SetCode(isolate, SQLITE_DONE, "SQLITE_DONE");
|
|
61
|
+
|
|
62
|
+
SetCode(isolate, SQLITE_ERROR_MISSING_COLLSEQ, "SQLITE_ERROR_MISSING_COLLSEQ");
|
|
63
|
+
SetCode(isolate, SQLITE_ERROR_RETRY, "SQLITE_ERROR_RETRY");
|
|
64
|
+
SetCode(isolate, SQLITE_ERROR_SNAPSHOT, "SQLITE_ERROR_SNAPSHOT");
|
|
65
|
+
SetCode(isolate, SQLITE_IOERR_READ, "SQLITE_IOERR_READ");
|
|
66
|
+
SetCode(isolate, SQLITE_IOERR_SHORT_READ, "SQLITE_IOERR_SHORT_READ");
|
|
67
|
+
SetCode(isolate, SQLITE_IOERR_WRITE, "SQLITE_IOERR_WRITE");
|
|
68
|
+
SetCode(isolate, SQLITE_IOERR_FSYNC, "SQLITE_IOERR_FSYNC");
|
|
69
|
+
SetCode(isolate, SQLITE_IOERR_DIR_FSYNC, "SQLITE_IOERR_DIR_FSYNC");
|
|
70
|
+
SetCode(isolate, SQLITE_IOERR_TRUNCATE, "SQLITE_IOERR_TRUNCATE");
|
|
71
|
+
SetCode(isolate, SQLITE_IOERR_FSTAT, "SQLITE_IOERR_FSTAT");
|
|
72
|
+
SetCode(isolate, SQLITE_IOERR_UNLOCK, "SQLITE_IOERR_UNLOCK");
|
|
73
|
+
SetCode(isolate, SQLITE_IOERR_RDLOCK, "SQLITE_IOERR_RDLOCK");
|
|
74
|
+
SetCode(isolate, SQLITE_IOERR_DELETE, "SQLITE_IOERR_DELETE");
|
|
75
|
+
SetCode(isolate, SQLITE_IOERR_BLOCKED, "SQLITE_IOERR_BLOCKED");
|
|
76
|
+
SetCode(isolate, SQLITE_IOERR_NOMEM, "SQLITE_IOERR_NOMEM");
|
|
77
|
+
SetCode(isolate, SQLITE_IOERR_ACCESS, "SQLITE_IOERR_ACCESS");
|
|
78
|
+
SetCode(isolate, SQLITE_IOERR_CHECKRESERVEDLOCK, "SQLITE_IOERR_CHECKRESERVEDLOCK");
|
|
79
|
+
SetCode(isolate, SQLITE_IOERR_LOCK, "SQLITE_IOERR_LOCK");
|
|
80
|
+
SetCode(isolate, SQLITE_IOERR_CLOSE, "SQLITE_IOERR_CLOSE");
|
|
81
|
+
SetCode(isolate, SQLITE_IOERR_DIR_CLOSE, "SQLITE_IOERR_DIR_CLOSE");
|
|
82
|
+
SetCode(isolate, SQLITE_IOERR_SHMOPEN, "SQLITE_IOERR_SHMOPEN");
|
|
83
|
+
SetCode(isolate, SQLITE_IOERR_SHMSIZE, "SQLITE_IOERR_SHMSIZE");
|
|
84
|
+
SetCode(isolate, SQLITE_IOERR_SHMLOCK, "SQLITE_IOERR_SHMLOCK");
|
|
85
|
+
SetCode(isolate, SQLITE_IOERR_SHMMAP, "SQLITE_IOERR_SHMMAP");
|
|
86
|
+
SetCode(isolate, SQLITE_IOERR_SEEK, "SQLITE_IOERR_SEEK");
|
|
87
|
+
SetCode(isolate, SQLITE_IOERR_DELETE_NOENT, "SQLITE_IOERR_DELETE_NOENT");
|
|
88
|
+
SetCode(isolate, SQLITE_IOERR_MMAP, "SQLITE_IOERR_MMAP");
|
|
89
|
+
SetCode(isolate, SQLITE_IOERR_GETTEMPPATH, "SQLITE_IOERR_GETTEMPPATH");
|
|
90
|
+
SetCode(isolate, SQLITE_IOERR_CONVPATH, "SQLITE_IOERR_CONVPATH");
|
|
91
|
+
SetCode(isolate, SQLITE_IOERR_VNODE, "SQLITE_IOERR_VNODE");
|
|
92
|
+
SetCode(isolate, SQLITE_IOERR_AUTH, "SQLITE_IOERR_AUTH");
|
|
93
|
+
SetCode(isolate, SQLITE_IOERR_BEGIN_ATOMIC, "SQLITE_IOERR_BEGIN_ATOMIC");
|
|
94
|
+
SetCode(isolate, SQLITE_IOERR_COMMIT_ATOMIC, "SQLITE_IOERR_COMMIT_ATOMIC");
|
|
95
|
+
SetCode(isolate, SQLITE_IOERR_ROLLBACK_ATOMIC, "SQLITE_IOERR_ROLLBACK_ATOMIC");
|
|
96
|
+
SetCode(isolate, SQLITE_IOERR_DATA, "SQLITE_IOERR_DATA");
|
|
97
|
+
SetCode(isolate, SQLITE_IOERR_CORRUPTFS, "SQLITE_IOERR_CORRUPTFS");
|
|
98
|
+
SetCode(isolate, SQLITE_IOERR_IN_PAGE, "SQLITE_IOERR_IN_PAGE");
|
|
99
|
+
SetCode(isolate, SQLITE_LOCKED_SHAREDCACHE, "SQLITE_LOCKED_SHAREDCACHE");
|
|
100
|
+
SetCode(isolate, SQLITE_LOCKED_VTAB, "SQLITE_LOCKED_VTAB");
|
|
101
|
+
SetCode(isolate, SQLITE_BUSY_RECOVERY, "SQLITE_BUSY_RECOVERY");
|
|
102
|
+
SetCode(isolate, SQLITE_BUSY_SNAPSHOT, "SQLITE_BUSY_SNAPSHOT");
|
|
103
|
+
SetCode(isolate, SQLITE_CANTOPEN_NOTEMPDIR, "SQLITE_CANTOPEN_NOTEMPDIR");
|
|
104
|
+
SetCode(isolate, SQLITE_CANTOPEN_ISDIR, "SQLITE_CANTOPEN_ISDIR");
|
|
105
|
+
SetCode(isolate, SQLITE_CANTOPEN_FULLPATH, "SQLITE_CANTOPEN_FULLPATH");
|
|
106
|
+
SetCode(isolate, SQLITE_CANTOPEN_CONVPATH, "SQLITE_CANTOPEN_CONVPATH");
|
|
107
|
+
SetCode(isolate, SQLITE_CANTOPEN_DIRTYWAL, "SQLITE_CANTOPEN_DIRTYWAL");
|
|
108
|
+
SetCode(isolate, SQLITE_CANTOPEN_SYMLINK, "SQLITE_CANTOPEN_SYMLINK");
|
|
109
|
+
SetCode(isolate, SQLITE_CORRUPT_VTAB, "SQLITE_CORRUPT_VTAB");
|
|
110
|
+
SetCode(isolate, SQLITE_CORRUPT_SEQUENCE, "SQLITE_CORRUPT_SEQUENCE");
|
|
111
|
+
SetCode(isolate, SQLITE_CORRUPT_INDEX, "SQLITE_CORRUPT_INDEX");
|
|
112
|
+
SetCode(isolate, SQLITE_READONLY_RECOVERY, "SQLITE_READONLY_RECOVERY");
|
|
113
|
+
SetCode(isolate, SQLITE_READONLY_CANTLOCK, "SQLITE_READONLY_CANTLOCK");
|
|
114
|
+
SetCode(isolate, SQLITE_READONLY_ROLLBACK, "SQLITE_READONLY_ROLLBACK");
|
|
115
|
+
SetCode(isolate, SQLITE_READONLY_DBMOVED, "SQLITE_READONLY_DBMOVED");
|
|
116
|
+
SetCode(isolate, SQLITE_READONLY_CANTINIT, "SQLITE_READONLY_CANTINIT");
|
|
117
|
+
SetCode(isolate, SQLITE_READONLY_DIRECTORY, "SQLITE_READONLY_DIRECTORY");
|
|
118
|
+
SetCode(isolate, SQLITE_ABORT_ROLLBACK, "SQLITE_ABORT_ROLLBACK");
|
|
119
|
+
SetCode(isolate, SQLITE_CONSTRAINT_CHECK, "SQLITE_CONSTRAINT_CHECK");
|
|
120
|
+
SetCode(isolate, SQLITE_CONSTRAINT_COMMITHOOK, "SQLITE_CONSTRAINT_COMMITHOOK");
|
|
121
|
+
SetCode(isolate, SQLITE_CONSTRAINT_FOREIGNKEY, "SQLITE_CONSTRAINT_FOREIGNKEY");
|
|
122
|
+
SetCode(isolate, SQLITE_CONSTRAINT_FUNCTION, "SQLITE_CONSTRAINT_FUNCTION");
|
|
123
|
+
SetCode(isolate, SQLITE_CONSTRAINT_NOTNULL, "SQLITE_CONSTRAINT_NOTNULL");
|
|
124
|
+
SetCode(isolate, SQLITE_CONSTRAINT_PRIMARYKEY, "SQLITE_CONSTRAINT_PRIMARYKEY");
|
|
125
|
+
SetCode(isolate, SQLITE_CONSTRAINT_TRIGGER, "SQLITE_CONSTRAINT_TRIGGER");
|
|
126
|
+
SetCode(isolate, SQLITE_CONSTRAINT_UNIQUE, "SQLITE_CONSTRAINT_UNIQUE");
|
|
127
|
+
SetCode(isolate, SQLITE_CONSTRAINT_VTAB, "SQLITE_CONSTRAINT_VTAB");
|
|
128
|
+
SetCode(isolate, SQLITE_CONSTRAINT_ROWID, "SQLITE_CONSTRAINT_ROWID");
|
|
129
|
+
SetCode(isolate, SQLITE_CONSTRAINT_PINNED, "SQLITE_CONSTRAINT_PINNED");
|
|
130
|
+
SetCode(isolate, SQLITE_CONSTRAINT_DATATYPE, "SQLITE_CONSTRAINT_DATATYPE");
|
|
131
|
+
SetCode(isolate, SQLITE_NOTICE_RECOVER_WAL, "SQLITE_NOTICE_RECOVER_WAL");
|
|
132
|
+
SetCode(isolate, SQLITE_NOTICE_RECOVER_ROLLBACK, "SQLITE_NOTICE_RECOVER_ROLLBACK");
|
|
133
|
+
SetCode(isolate, SQLITE_NOTICE_RBU, "SQLITE_NOTICE_RBU");
|
|
134
|
+
SetCode(isolate, SQLITE_WARNING_AUTOINDEX, "SQLITE_WARNING_AUTOINDEX");
|
|
135
|
+
SetCode(isolate, SQLITE_AUTH_USER, "SQLITE_AUTH_USER");
|
|
136
|
+
SetCode(isolate, SQLITE_OK_LOAD_PERMANENTLY, "SQLITE_OK_LOAD_PERMANENTLY");
|
|
137
|
+
SetCode(isolate, SQLITE_OK_SYMLINK, "SQLITE_OK_SYMLINK");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
v8::Global<v8::String> database;
|
|
141
|
+
v8::Global<v8::String> reader;
|
|
142
|
+
v8::Global<v8::String> source;
|
|
143
|
+
v8::Global<v8::String> memory;
|
|
144
|
+
v8::Global<v8::String> readonly;
|
|
145
|
+
v8::Global<v8::String> name;
|
|
146
|
+
v8::Global<v8::String> next;
|
|
147
|
+
v8::Global<v8::String> length;
|
|
148
|
+
v8::Global<v8::String> done;
|
|
149
|
+
v8::Global<v8::String> value;
|
|
150
|
+
v8::Global<v8::String> changes;
|
|
151
|
+
v8::Global<v8::String> lastInsertRowid;
|
|
152
|
+
v8::Global<v8::String> statement;
|
|
153
|
+
v8::Global<v8::String> column;
|
|
154
|
+
v8::Global<v8::String> table;
|
|
155
|
+
v8::Global<v8::String> type;
|
|
156
|
+
v8::Global<v8::String> totalPages;
|
|
157
|
+
v8::Global<v8::String> remainingPages;
|
|
158
|
+
|
|
159
|
+
private:
|
|
160
|
+
|
|
161
|
+
static void SetString(v8::Isolate* isolate, v8::Global<v8::String>& constant, const char* str) {
|
|
162
|
+
constant.Reset(isolate, InternalizedFromLatin1(isolate, str));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
void SetCode(v8::Isolate* isolate, int code, const char* str) {
|
|
166
|
+
codes.emplace(std::piecewise_construct,
|
|
167
|
+
std::forward_as_tuple(code),
|
|
168
|
+
std::forward_as_tuple(isolate, InternalizedFromLatin1(isolate, str)));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
std::unordered_map<int, v8::Global<v8::String> > codes;
|
|
172
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
class CustomAggregate : public CustomFunction {
|
|
2
|
+
public:
|
|
3
|
+
|
|
4
|
+
explicit CustomAggregate(
|
|
5
|
+
v8::Isolate* isolate,
|
|
6
|
+
Database* db,
|
|
7
|
+
const char* name,
|
|
8
|
+
v8::Local<v8::Value> start,
|
|
9
|
+
v8::Local<v8::Function> step,
|
|
10
|
+
v8::Local<v8::Value> inverse,
|
|
11
|
+
v8::Local<v8::Value> result,
|
|
12
|
+
bool safe_ints
|
|
13
|
+
) :
|
|
14
|
+
CustomFunction(isolate, db, name, step, safe_ints),
|
|
15
|
+
invoke_result(result->IsFunction()),
|
|
16
|
+
invoke_start(start->IsFunction()),
|
|
17
|
+
inverse(isolate, inverse->IsFunction() ? inverse.As<v8::Function>() : v8::Local<v8::Function>()),
|
|
18
|
+
result(isolate, result->IsFunction() ? result.As<v8::Function>() : v8::Local<v8::Function>()),
|
|
19
|
+
start(isolate, start) {}
|
|
20
|
+
|
|
21
|
+
static void xStep(sqlite3_context* invocation, int argc, sqlite3_value** argv) {
|
|
22
|
+
xStepBase(invocation, argc, argv, &CustomAggregate::fn);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static void xInverse(sqlite3_context* invocation, int argc, sqlite3_value** argv) {
|
|
26
|
+
xStepBase(invocation, argc, argv, &CustomAggregate::inverse);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static void xValue(sqlite3_context* invocation) {
|
|
30
|
+
xValueBase(invocation, false);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static void xFinal(sqlite3_context* invocation) {
|
|
34
|
+
xValueBase(invocation, true);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private:
|
|
38
|
+
|
|
39
|
+
static inline void xStepBase(sqlite3_context* invocation, int argc, sqlite3_value** argv, const v8::Global<v8::Function> CustomAggregate::*ptrtm) {
|
|
40
|
+
AGGREGATE_START();
|
|
41
|
+
|
|
42
|
+
v8::Local<v8::Value> args_fast[5];
|
|
43
|
+
v8::Local<v8::Value>* args = argc <= 4 ? args_fast : ALLOC_ARRAY<v8::Local<v8::Value>>(argc + 1);
|
|
44
|
+
args[0] = acc->value.Get(isolate);
|
|
45
|
+
if (argc != 0) Data::GetArgumentsJS(isolate, args + 1, argv, argc, self->safe_ints);
|
|
46
|
+
|
|
47
|
+
v8::MaybeLocal<v8::Value> maybeReturnValue = (self->*ptrtm).Get(isolate)->Call(OnlyContext, v8::Undefined(isolate), argc + 1, args);
|
|
48
|
+
if (args != args_fast) delete[] args;
|
|
49
|
+
|
|
50
|
+
if (maybeReturnValue.IsEmpty()) {
|
|
51
|
+
self->PropagateJSError(invocation);
|
|
52
|
+
} else {
|
|
53
|
+
v8::Local<v8::Value> returnValue = maybeReturnValue.ToLocalChecked();
|
|
54
|
+
if (!returnValue->IsUndefined()) acc->value.Reset(isolate, returnValue);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static inline void xValueBase(sqlite3_context* invocation, bool is_final) {
|
|
59
|
+
AGGREGATE_START();
|
|
60
|
+
|
|
61
|
+
if (!is_final) {
|
|
62
|
+
acc->is_window = true;
|
|
63
|
+
} else if (acc->is_window) {
|
|
64
|
+
DestroyAccumulator(invocation);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
v8::Local<v8::Value> result = acc->value.Get(isolate);
|
|
69
|
+
if (self->invoke_result) {
|
|
70
|
+
v8::MaybeLocal<v8::Value> maybeResult = self->result.Get(isolate)->Call(OnlyContext, v8::Undefined(isolate), 1, &result);
|
|
71
|
+
if (maybeResult.IsEmpty()) {
|
|
72
|
+
self->PropagateJSError(invocation);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
result = maybeResult.ToLocalChecked();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
Data::ResultValueFromJS(isolate, invocation, result, self);
|
|
79
|
+
if (is_final) DestroyAccumulator(invocation);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
struct Accumulator { public:
|
|
83
|
+
v8::Global<v8::Value> value;
|
|
84
|
+
bool initialized;
|
|
85
|
+
bool is_window;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
Accumulator* GetAccumulator(sqlite3_context* invocation) {
|
|
89
|
+
Accumulator* acc = static_cast<Accumulator*>(sqlite3_aggregate_context(invocation, sizeof(Accumulator)));
|
|
90
|
+
if (!acc->initialized) {
|
|
91
|
+
assert(acc->value.IsEmpty());
|
|
92
|
+
acc->initialized = true;
|
|
93
|
+
if (invoke_start) {
|
|
94
|
+
v8::MaybeLocal<v8::Value> maybeSeed = start.Get(isolate).As<v8::Function>()->Call(OnlyContext, v8::Undefined(isolate), 0, NULL);
|
|
95
|
+
if (maybeSeed.IsEmpty()) PropagateJSError(invocation);
|
|
96
|
+
else acc->value.Reset(isolate, maybeSeed.ToLocalChecked());
|
|
97
|
+
} else {
|
|
98
|
+
assert(!start.IsEmpty());
|
|
99
|
+
acc->value.Reset(isolate, start);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return acc;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static void DestroyAccumulator(sqlite3_context* invocation) {
|
|
106
|
+
Accumulator* acc = static_cast<Accumulator*>(sqlite3_aggregate_context(invocation, sizeof(Accumulator)));
|
|
107
|
+
assert(acc->initialized);
|
|
108
|
+
acc->value.Reset();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
void PropagateJSError(sqlite3_context* invocation) {
|
|
112
|
+
DestroyAccumulator(invocation);
|
|
113
|
+
CustomFunction::PropagateJSError(invocation);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const bool invoke_result;
|
|
117
|
+
const bool invoke_start;
|
|
118
|
+
const v8::Global<v8::Function> inverse;
|
|
119
|
+
const v8::Global<v8::Function> result;
|
|
120
|
+
const v8::Global<v8::Value> start;
|
|
121
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
class CustomFunction : protected DataConverter {
|
|
2
|
+
public:
|
|
3
|
+
|
|
4
|
+
explicit CustomFunction(
|
|
5
|
+
v8::Isolate* isolate,
|
|
6
|
+
Database* db,
|
|
7
|
+
const char* name,
|
|
8
|
+
v8::Local<v8::Function> fn,
|
|
9
|
+
bool safe_ints
|
|
10
|
+
) :
|
|
11
|
+
name(name),
|
|
12
|
+
db(db),
|
|
13
|
+
isolate(isolate),
|
|
14
|
+
fn(isolate, fn),
|
|
15
|
+
safe_ints(safe_ints) {}
|
|
16
|
+
|
|
17
|
+
virtual ~CustomFunction() {}
|
|
18
|
+
|
|
19
|
+
static void xDestroy(void* self) {
|
|
20
|
+
delete static_cast<CustomFunction*>(self);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static void xFunc(sqlite3_context* invocation, int argc, sqlite3_value** argv) {
|
|
24
|
+
FUNCTION_START();
|
|
25
|
+
|
|
26
|
+
v8::Local<v8::Value> args_fast[4];
|
|
27
|
+
v8::Local<v8::Value>* args = NULL;
|
|
28
|
+
if (argc != 0) {
|
|
29
|
+
args = argc <= 4 ? args_fast : ALLOC_ARRAY<v8::Local<v8::Value>>(argc);
|
|
30
|
+
Data::GetArgumentsJS(isolate, args, argv, argc, self->safe_ints);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
v8::MaybeLocal<v8::Value> maybeReturnValue = self->fn.Get(isolate)->Call(OnlyContext, v8::Undefined(isolate), argc, args);
|
|
34
|
+
if (args != args_fast) delete[] args;
|
|
35
|
+
|
|
36
|
+
if (maybeReturnValue.IsEmpty()) self->PropagateJSError(invocation);
|
|
37
|
+
else Data::ResultValueFromJS(isolate, invocation, maybeReturnValue.ToLocalChecked(), self);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protected:
|
|
41
|
+
|
|
42
|
+
void PropagateJSError(sqlite3_context* invocation) {
|
|
43
|
+
assert(db->GetState()->was_js_error == false);
|
|
44
|
+
db->GetState()->was_js_error = true;
|
|
45
|
+
sqlite3_result_error(invocation, "", 0);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
std::string GetDataErrorPrefix() {
|
|
49
|
+
return std::string("User-defined function ") + name + "() returned";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private:
|
|
53
|
+
const std::string name;
|
|
54
|
+
Database* const db;
|
|
55
|
+
protected:
|
|
56
|
+
v8::Isolate* const isolate;
|
|
57
|
+
const v8::Global<v8::Function> fn;
|
|
58
|
+
const bool safe_ints;
|
|
59
|
+
};
|