Skip to content

Commit ebddd39

Browse files
committed
cleanup: merge polyfills and benchmark.js into single file
1 parent cbce1b8 commit ebddd39

File tree

3 files changed

+32
-34
lines changed

3 files changed

+32
-34
lines changed

JetStreamDriver.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,9 +2013,8 @@ const BENCHMARKS = [
20132013
new WasmEMCCBenchmark({
20142014
name: "sqlite3-wasm",
20152015
files: [
2016-
"./sqlite3/polyfills.js",
2017-
"./sqlite3/build/jswasm/speedtest1.js",
20182016
"./sqlite3/benchmark.js",
2017+
"./sqlite3/build/jswasm/speedtest1.js",
20192018
],
20202019
preload: {
20212020
wasmBinary: "./sqlite3/build/jswasm/speedtest1.wasm"

sqlite3/benchmark.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,37 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// Since a small portion of the setup of code of SQLite is run immediately
6-
// when loading it, some polyfills are split out of this file and loaded first.
5+
// First, some polyfills for missing browser APIs in JavaScript shells.
6+
// Since the generated JavaScript code of SQLite immediately uses some of them,
7+
// we need to load and run this code before the generated `speedtest1.js` in the
8+
// JetStream driver.
9+
10+
// Empty `URLSearchParams` has just the same interface as a `Map`.
11+
globalThis.URLSearchParams = Map;
12+
13+
// `TextEncoder` and `TextDecoder`. These are called only a few times with short
14+
// ASCII strings, so this is sufficient and not performance-critical.
15+
class TextEncoder {
16+
encode(string) {
17+
return Uint8Array.from(string, (char) => {
18+
let byte = char.codePointAt(0);
19+
if (byte > 0x7f)
20+
throw new Error("TextEncoder polyfill only supports ASCII");
21+
return byte;
22+
});
23+
}
24+
}
25+
class TextDecoder {
26+
decode(array) {
27+
for (let byte of array) {
28+
if (byte > 0x7f)
29+
throw new Error("TextDecoder polyfill only supports ASCII");
30+
}
31+
return String.fromCharCode.apply(null, array);
32+
}
33+
}
34+
35+
// Now, some configuration options for when we initialize SQLite.
736

837
// Use JetStream functions instead of `console.log` and friends.
938
globalThis.sqlite3ApiConfig = {

sqlite3/polyfills.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)