Skip to content

Commit 0336907

Browse files
committed
docs?
1 parent 7b4ed54 commit 0336907

File tree

6 files changed

+288
-94
lines changed

6 files changed

+288
-94
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"make-release": "make clean && make -j 8",
1818
"clean": "make clean",
1919
"build": "tsc",
20-
"test": "mocha",
21-
"watch": "tsc --watch",
22-
"prettier": "prettier --write ./package.json ./**/*.ts",
20+
"doc": "typedoc --plugin typedoc-plugin-markdown",
21+
"test": "yarn make-debug && mocha",
22+
"prettier": "prettier --write ./*.json ./**/*.ts ./*.js",
2323
"run-ts": "yarn make-debug && ts-node -T ./ts/examples/hello.ts",
2424
"run-n": "yarn make-debug && ./build/wrapper/native/test.exe"
2525
},
@@ -31,6 +31,8 @@
3131
"prettier": "^1.19.1",
3232
"source-map-support": "^0.5.16",
3333
"ts-node": "^8.5.4",
34+
"typedoc": "^0.15.8",
35+
"typedoc-plugin-markdown": "^2.2.16",
3436
"typescript": "^3.7.4"
3537
}
3638
}

ts/examples/hello.ts

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

ts/quickjs.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ import {
1616
} from './types'
1717

1818
let isReady = false
19+
1920
const QuickJSModule = QuickJSModuleLoader()
20-
export const ready = new Promise(resolve => {
21+
22+
/**
23+
* This promise will be fufilled when the QuickJS emscripten module has initialized
24+
* and the {@link QuickJS} instance can be created.
25+
*/
26+
const ready = new Promise(resolve => {
2127
QuickJSModule.onRuntimeInitialized = resolve
2228
}).then(() => {
2329
isReady = true
@@ -68,6 +74,16 @@ class Lifetime<T, Owner = never> {
6874
}
6975
}
7076

77+
/**
78+
* QuickJSVm wraps a QuickJS Javascript runtime (JSRuntime*) and context (JSContext*).
79+
* This class's methods return {@link QuickJSHandle}, which wrap C pointers (JSValue*).
80+
* It's the caller's responsibility to call {@link QuickJSHandle#dispose} on any
81+
* handles you create to free memory once you're done with the handle.
82+
*
83+
* You cannot share handles between different QuickJSVm instances.
84+
*
85+
* @see {@link QuickJS#createVm} Creates a new QuickJSVm
86+
*/
7187
export class QuickJSVm implements LowLevelJavascriptVm<QuickJSHandle> {
7288
readonly ctx: Lifetime<JSContextPointer>
7389
readonly rt: Lifetime<JSRuntimePointer>
@@ -101,6 +117,10 @@ export class QuickJSVm implements LowLevelJavascriptVm<QuickJSHandle> {
101117
return (this._undefined = new Lifetime(ptr))
102118
}
103119

120+
/**
121+
* A handle to the global object inside the interpreter.
122+
* You can set properties to create global variables.
123+
*/
104124
get global() {
105125
if (this._global) {
106126
return this._global
@@ -305,6 +325,11 @@ export class QuickJSVm implements LowLevelJavascriptVm<QuickJSHandle> {
305325
return result.value
306326
}
307327

328+
/**
329+
* Dispose of this VM's underlying resources.
330+
* Calling this method without disposing of all created handles will result
331+
* in an error.
332+
*/
308333
dispose() {
309334
for (const lifetime of this.lifetimes) {
310335
if (lifetime.alive) {
@@ -318,6 +343,9 @@ export class QuickJSVm implements LowLevelJavascriptVm<QuickJSHandle> {
318343
private fnNextId = 0
319344
private fnMap = new Map<number, VmFunctionImplementation<QuickJSHandle>>()
320345

346+
/**
347+
* @private
348+
*/
321349
cToHostCallbackFunction: CToHostCallbackFunctionImplementation = (
322350
ctx,
323351
this_ptr,
@@ -449,6 +477,14 @@ export type QuickJSHandle = StaticJSValue | JSValue | JSValueConst
449477
/**
450478
* QuickJS presents a Javascript interface to QuickJS, a Javascript interpreter that
451479
* supports ES2019.
480+
*
481+
* QuickJS is a singleton. Use the {@link getInstance} function to instantiate
482+
* or retrieve an instance.
483+
*
484+
* Use the {@link QuickJS#createVm} method to create a {@link QuickJSVm}.
485+
*
486+
* Use the {@link QuickJS#evalCode} method as a shortcut evaluate Javascript safely
487+
* and return the result as a native Javascript value.
452488
*/
453489
export class QuickJS {
454490
private ffi = new QuickJSFFI(QuickJSModule)
@@ -512,6 +548,8 @@ export class QuickJS {
512548

513549
/**
514550
* One-off evaluate code without needing to create a VM.
551+
* The result is coerced to a native Javascript value using JSON
552+
* serialization, so values unsupported by JSON will be dropped.
515553
*/
516554
evalCode(code: string): unknown {
517555
const vm = this.createVm()

tsconfig.json

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
{
2-
"include": ["ts/**/*.ts", "ts/**/*.js", "build/wrapper/**/*.js", "build/wrapper/**/*.wasm", "build/wrapper/**/*.ts"],
2+
"include": [
3+
"ts/**/*.ts",
4+
"ts/**/*.js",
5+
"build/wrapper/**/*.js",
6+
"build/wrapper/**/*.wasm",
7+
"build/wrapper/**/*.ts"
8+
],
39
"exclude": ["node_modules"],
410
"compilerOptions": {
511
/* Basic Options */
6-
"incremental": true, /* Enable incremental compilation */
7-
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
8-
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
12+
"incremental": true /* Enable incremental compilation */,
13+
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
14+
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
915

10-
"lib": ["es2015", "dom"], /* Specify library files to be included in the compilation. */
11-
"allowJs": true, /* Allow javascript files to be compiled. */
16+
"lib": ["es2015", "dom"] /* Specify library files to be included in the compilation. */,
17+
"allowJs": true /* Allow javascript files to be compiled. */,
1218
// "checkJs": true, /* Report errors in .js files. */
1319
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
14-
"declaration": true, /* Generates corresponding '.d.ts' file. */
20+
"declaration": true /* Generates corresponding '.d.ts' file. */,
1521
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
16-
"sourceMap": true, /* Generates corresponding '.map' file. */
22+
"sourceMap": true /* Generates corresponding '.map' file. */,
1723
// "outFile": "./", /* Concatenate and emit output to single file. */
18-
"outDir": "./build/js", /* Redirect output structure to the directory. */
24+
"outDir": "./build/js" /* Redirect output structure to the directory. */,
1925
// "composite": true, /* Enable project compilation */
2026
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
2127
// "removeComments": true, /* Do not emit comments to output. */
@@ -25,7 +31,7 @@
2531
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
2632

2733
/* Strict Type-Checking Options */
28-
"strict": true, /* Enable all strict type-checking options. */
34+
"strict": true /* Enable all strict type-checking options. */,
2935
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
3036
// "strictNullChecks": true, /* Enable strict null checks. */
3137
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
@@ -35,23 +41,23 @@
3541
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
3642

3743
/* Additional Checks */
38-
"noUnusedLocals": true, /* Report errors on unused locals. */
44+
"noUnusedLocals": true /* Report errors on unused locals. */,
3945
// "noUnusedParameters": true, /* Report errors on unused parameters. */
40-
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
41-
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
46+
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
47+
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
4248

4349
/* Module Resolution Options */
44-
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
50+
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
4551
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
4652
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
4753
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
4854
"typeRoots": [
4955
"node_modules/@types",
50-
"./node_modules/@snyk/types-tap",
51-
], /* List of folders to include type definitions from. */
56+
"./node_modules/@snyk/types-tap"
57+
] /* List of folders to include type definitions from. */,
5258
// "types": [], /* Type declaration files to be included in compilation. */
5359
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
54-
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
60+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
5561
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
5662
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
5763

@@ -66,6 +72,6 @@
6672
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
6773

6874
/* Advanced Options */
69-
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
75+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
7076
}
7177
}

typedoc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const NO_THANKS = ['**/node_modules/**', './quickjs/**']
2+
3+
function escapeEntrypoint(str) {
4+
const wanted = 1
5+
let out = str
6+
for (let i = 0; i < wanted; i++) {
7+
out = JSON.stringify(out)
8+
}
9+
return out
10+
}
11+
12+
module.exports = {
13+
out: './doc',
14+
//entryPoint: escapeEntrypoint('ts/quickjs'),
15+
exclude: NO_THANKS,
16+
externalsPattern: NO_THANKS[0],
17+
excludeNotExported: true,
18+
excludePrivate: true,
19+
ignoreCompilerErrors: true,
20+
}

0 commit comments

Comments
 (0)