Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init cleanup #416

Merged
merged 3 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ jobs:
sudo apt install -y gcc-12 g++-12 libpthread-stubs0-dev libwebkit2gtk-4.1-dev

- name: Gradle cache
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v2.4.2
with:
gradle-version: 7.6.1

Expand Down
72 changes: 36 additions & 36 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,15 @@ Start advertising a new value for a well-known UUID
import { randomBytes } from 'socket:crypto'
```

## [ready](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L48)
## [webcrypto](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L23)

A promise that resolves when all internals to be loaded/ready.
WebCrypto API

## [webcrypto](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L61)
## [ready](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L52)

WebCrypto API
A promise that resolves when all internals to be loaded/ready.

## [`getRandomValues(buffer)`](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L69)
## [`getRandomValues(buffer)`](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L67)

External docs: https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues

Expand All @@ -355,24 +355,24 @@ Generate cryptographically strong random values into the `buffer`
| Not specified | TypedArray | |


## [`rand64()`](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L90)
## [`rand64()`](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L86)

This is a `FunctionDeclaration` named `rand64` in `api/crypto.js`, it's exported but undocumented.


## [RANDOM_BYTES_QUOTA](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L98)
## [RANDOM_BYTES_QUOTA](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L94)

Maximum total size of random bytes per page

## [MAX_RANDOM_BYTES](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L103)
## [MAX_RANDOM_BYTES](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L99)

Maximum total size for random bytes.

## [MAX_RANDOM_BYTES_PAGES](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L108)
## [MAX_RANDOM_BYTES_PAGES](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L104)

Maximum total amount of allocated per page of bytes (max/quota)

## [`randomBytes(size)`](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L116)
## [`randomBytes(size)`](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L112)

Generate `size` random bytes.

Expand All @@ -386,7 +386,7 @@ Generate `size` random bytes.
| Not specified | Buffer | A promise that resolves with an instance of socket.Buffer with random bytes. |


## [`createDigest(algorithm, message)`](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L143)
## [`createDigest(algorithm, message)`](https://github.com/socketsupply/socket/blob/master/api/crypto.js#L139)



Expand Down Expand Up @@ -1402,11 +1402,11 @@ Starts the process of connecting to the network.
import { Path } from 'socket:path'
```

## [`Path` (extends `URL`)](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L31)
## [`Path` (extends `URL`)](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L32)

A container for a parsed Path.

### [`cwd(opts)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L38)
### [`cwd(opts)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L39)

Computes current working directory for a path

Expand All @@ -1421,7 +1421,7 @@ Computes current working directory for a path
| Not specified | string | |


### [`resolve(options, components)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L56)
### [`resolve(options, components)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L58)

Resolves path components to an absolute path.

Expand All @@ -1436,7 +1436,7 @@ Resolves path components to an absolute path.
| Not specified | string | |


### [`relative(options, from, to)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L84)
### [`relative(options, from, to)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L86)

Computes the relative path from `from` to `to`.

Expand All @@ -1452,7 +1452,7 @@ Computes the relative path from `from` to `to`.
| Not specified | string | |


### [`join(options, components)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L131)
### [`join(options, components)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L133)

Joins path components. This function may not return an absolute path.

Expand All @@ -1467,7 +1467,7 @@ Joins path components. This function may not return an absolute path.
| Not specified | string | |


### [`dirname(options, components)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L161)
### [`dirname(options, components)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L163)

Computes directory name of path.

Expand All @@ -1482,7 +1482,7 @@ Computes directory name of path.
| Not specified | string | |


### [`basename(options, components)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L199)
### [`basename(options, components)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L235)

Computes base name of path.

Expand All @@ -1497,7 +1497,7 @@ Computes base name of path.
| Not specified | string | |


### [`extname(options, path)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L217)
### [`extname(options, path)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L250)

Computes extension name of path.

Expand All @@ -1512,7 +1512,7 @@ Computes extension name of path.
| Not specified | string | |


### [`normalize(options, path)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L228)
### [`normalize(options, path)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L261)

Computes normalized path

Expand All @@ -1527,7 +1527,7 @@ Computes normalized path
| Not specified | string | |


### [`format(options, path)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L275)
### [`format(options, path)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L311)

Formats `Path` object into a string.

Expand All @@ -1542,7 +1542,7 @@ Formats `Path` object into a string.
| Not specified | string | |


### [`parse(path)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L291)
### [`parse(path)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L327)

Parses input `path` into a `Path` instance.

Expand All @@ -1556,7 +1556,7 @@ Parses input `path` into a `Path` instance.
| Not specified | object | |


### [`from(input, cwd)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L317)
### [`from(input, cwd)`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L353)

Creates a `Path` instance from `input` and optional `cwd`.

Expand All @@ -1566,7 +1566,7 @@ Creates a `Path` instance from `input` and optional `cwd`.
| cwd | string | | false | |


### [`constructor(pathname, cwd )`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L338)
### [`constructor(pathname, cwd )`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L374)

`Path` class constructor.

Expand All @@ -1576,47 +1576,47 @@ Creates a `Path` instance from `input` and optional `cwd`.
| cwd | string | Path.cwd() | false | |


### [`isRelative()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L371)
### [`isRelative()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L407)

`true` if the path is relative, otherwise `false.

### [`value()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L378)
### [`value()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L414)

The working value of this path.

### [`source()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L389)
### [`source()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L425)

The original source, unresolved.

### [`parent()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L397)
### [`parent()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L433)

Computed parent path.

### [`root()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L415)
### [`root()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L451)

Computed root in path.

### [`dir()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L436)
### [`dir()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L472)

Computed directory name in path.

### [`base()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L471)
### [`base()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L507)

Computed base name in path.

### [`name()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L483)
### [`name()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L519)

Computed base name in path without path extension.

### [`ext()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L491)
### [`ext()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L527)

Computed extension name in path.

### [`drive()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L509)
### [`drive()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L545)

The computed drive, if given in the path.

### [`toURL()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L516)
### [`toURL()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L552)



Expand All @@ -1625,7 +1625,7 @@ The computed drive, if given in the path.
| Not specified | URL | |


### [`toString()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L524)
### [`toString()`](https://github.com/socketsupply/socket/blob/master/api/path/path.js#L560)

Converts this `Path` instance to a string.

Expand Down
12 changes: 6 additions & 6 deletions api/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ declare module "socket:util" {
export function isClass(value: any): boolean;
export function isPromiseLike(object: any): boolean;
export function toString(object: any): string;
export function toBuffer(object: any, encoding: any): any;
export function toBuffer(object: any, encoding?: any): any;
export function toProperCase(string: any): any;
export function splitBuffer(buffer: any, highWaterMark: any): any[];
export function InvertedPromise(): Promise<any>;
Expand Down Expand Up @@ -2156,16 +2156,16 @@ declare module "socket:crypto" {
* @returns {Promise<Buffer>} - A promise that resolves with an instance of socket.Buffer with the hash.
*/
export function createDigest(algorithm: string, buf: any): Promise<Buffer>;
/**
* WebCrypto API
* @see {https://developer.mozilla.org/en-US/docs/Web/API/Crypto}
*/
export let webcrypto: any;
/**
* A promise that resolves when all internals to be loaded/ready.
* @type {Promise}
*/
export const ready: Promise<any>;
/**
* WebCrypto API
* @see {https://developer.mozilla.org/en-US/docs/Web/API/Crypto}
*/
export const webcrypto: any;
/**
* Maximum total size of random bytes per page
*/
Expand Down
3 changes: 2 additions & 1 deletion api/internal/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class RuntimeXHRPostQueue extends ConcurrentQueue {

hooks.onLoad(() => {
if (typeof globalThis.dispatchEvent === 'function') {
globalThis.dispatchEvent(new CustomEvent('init'))
globalThis.dispatchEvent(new CustomEvent('__runtime_init__'))
}
})

Expand All @@ -307,4 +307,5 @@ hooks.onReady(async () => {
globals.register('RuntimeXHRPostQueue', new RuntimeXHRPostQueue())
// prevent further construction if this class is indirectly referenced
RuntimeXHRPostQueue.prototype.constructor = IllegalConstructor

export default applyPolyfills()
2 changes: 1 addition & 1 deletion api/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function toString (object) {
return Object.prototype.toString(object)
}

export function toBuffer (object, encoding) {
export function toBuffer (object, encoding = undefined) {
if (Buffer.isBuffer(object)) {
return object
} else if (isTypedArray(object)) {
Expand Down
11 changes: 10 additions & 1 deletion src/core/javascript.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@ namespace SSC {
String createJavaScript (const String& name, const String& source) {
return String(
";(async () => { \n"
" await new Promise((resolve) => { \n"
" if (globalThis.__RUNTIME_INIT_NOW__) { \n"
" resolve(); \n"
" } else { \n"
" globalThis.addEventListener('__runtime_init__', resolve); \n"
" } \n"
" }); \n"
" \n"
" console.assert( \n"
" typeof globalThis.__RUNTIME_INIT_NOW__ === 'number', \n"
" '__RUNTIME_INIT_NOW__ check failed. ' + \n"
" 'The webview environment may not be initialized correctly.' \n"
" ); \n"
" " + trim(source) + "; \n"
" \n"
" " + trim(source) + "; \n"
"})(); \n"
"//# sourceURL=" + name + " \n"
);
Expand Down