-
Notifications
You must be signed in to change notification settings - Fork 88
refactor(pass-style): faster isObject
#2860
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| import { isPromise } from '@endo/promise-kit'; | ||
| import { X, Fail, q, annotateError, makeError } from '@endo/errors'; | ||
| import { | ||
| isObject, | ||
| isPrimitive, | ||
| isTypedArray, | ||
| PASS_STYLE, | ||
| assertChecker, | ||
|
|
@@ -123,7 +123,7 @@ const makePassStyleOf = passStyleHelpers => { | |
| const inProgress = new Set(); | ||
|
|
||
| const passStyleOfRecur = inner => { | ||
| const innerIsObject = isObject(inner); | ||
| const innerIsObject = !isPrimitive(inner); | ||
| if (innerIsObject) { | ||
| const innerStyle = passStyleMemo.get(inner); | ||
| if (innerStyle) { | ||
|
|
@@ -359,11 +359,11 @@ export const toThrowable = specimen => { | |
| if (isErrorLike(specimen)) { | ||
| return toPassableError(/** @type {Error} */ (specimen)); | ||
| } | ||
| // Note that this step will fail if `specimen` would be a passable container | ||
| // except that it contains non-passable errors that could be converted. | ||
| // This will need to be fixed to do the TODO above. | ||
| const passStyle = passStyleOf(specimen); | ||
| if (isObject(specimen)) { | ||
| if (!isPrimitive(specimen)) { | ||
| // Note that this step will fail if `specimen` would be a passable container | ||
| // except that it contains non-passable errors that could be converted. | ||
| // This will need to be fixed to do the TODO above. | ||
| const passStyle = /** @type {PassStyle} */ (passStyleOf(specimen)); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving the call to |
||
| switch (passStyle) { | ||
| case 'copyArray': { | ||
| const elements = /** @type {CopyArray} */ (specimen); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,11 +25,24 @@ export type AtomStyle = | |
| | 'byteArray' | ||
| | 'symbol'; | ||
|
|
||
| /** | ||
| * The actual JS primitive types. | ||
| */ | ||
| export type JSPrimitive = | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made it easier to define the type of |
||
| | undefined | ||
| | null | ||
| | boolean | ||
| | number | ||
| | bigint | ||
| | string | ||
| | symbol; | ||
|
|
||
| /** | ||
| * @deprecated Use `Atom` instead, which is also the ocapn name. Now that | ||
| * ByteArray has been added, this category no longer corresponds to | ||
| * JS primitives, We also expect to move to a passable-symbol representation | ||
| * as a JS object, not a JS primitive | ||
| * as a JS object, not a JS primitive. But if you really do mean a JS primitive | ||
| * only, use `JSPrimitive` instead. | ||
| */ | ||
| export type Primitive = Atom; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pure-refactor drive-by