Skip to content

Commit

Permalink
feat: more membrane specific conditions to reduce checks when not nee…
Browse files Browse the repository at this point in the history
…ded (#332)
  • Loading branch information
jdalton authored Apr 12, 2022
1 parent d58beff commit 2d0cd0e
Show file tree
Hide file tree
Showing 2 changed files with 343 additions and 357 deletions.
30 changes: 7 additions & 23 deletions packages/near-membrane-base/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ interface VirtualEnvironmentOptions {
const LOCKER_NEAR_MEMBRANE_UNDEFINED_VALUE_SYMBOL = Symbol.for(
'@@lockerNearMembraneUndefinedValue'
);
const SHOULD_TRAP_MUTATION = true;
const SHOULD_NOT_TRAP_MUTATION = false;

const ArrayCtor = Array;
const ErrorCtor = Error;
const ObjectCtor = Object;
Expand All @@ -41,10 +38,6 @@ const { assign: ObjectAssign } = ObjectCtor;
const { apply: ReflectApply, ownKeys: ReflectOwnKeys } = Reflect;

export class VirtualEnvironment {
public readonly blueConnector: ReturnType<typeof createMembraneMarshall>;

public readonly redConnector: ReturnType<typeof createMembraneMarshall>;

private readonly blueCallableGetPropertyValuePointer: CallableGetPropertyValuePointer;

private readonly blueCallableLinkPointers: CallableLinkPointers;
Expand Down Expand Up @@ -82,11 +75,8 @@ export class VirtualEnvironment {
// eslint-disable-next-line prefer-object-spread
} = ObjectAssign({ __proto__: null }, providedOptions);
let blueHooks: Parameters<HooksCallback>;
let redHooks: Parameters<HooksCallback>;
// prettier-ignore
const localConnect = blueConnector(
const blueConnect = blueConnector(
'blue',
SHOULD_NOT_TRAP_MUTATION,
(...hooks) => {
blueHooks = hooks;
},
Expand All @@ -95,14 +85,6 @@ export class VirtualEnvironment {
instrumentation,
}
);
// prettier-ignore
const foreignConnect = redConnector(
'red',
SHOULD_TRAP_MUTATION,
(...hooks) => {
redHooks = hooks;
}
);
const {
0: blueGlobalThisPointer,
1: blueGetSelectedTarget,
Expand Down Expand Up @@ -139,6 +121,10 @@ export class VirtualEnvironment {
32: blueCallableBatchGetPrototypeOfWhenHasNoOwnProperty,
33: blueCallableBatchGetPrototypeOfWhenHasNoOwnPropertyDescriptor,
} = blueHooks!;
let redHooks: Parameters<HooksCallback>;
const redConnect = redConnector('red', (...hooks) => {
redHooks = hooks;
});
const {
0: redGlobalThisPointer,
1: redGetSelectedTarget,
Expand Down Expand Up @@ -175,7 +161,7 @@ export class VirtualEnvironment {
32: redCallableBatchGetPrototypeOfWhenHasNoOwnProperty,
33: redCallableBatchGetPrototypeOfWhenHasNoOwnPropertyDescriptor,
} = redHooks!;
localConnect(
blueConnect(
redGlobalThisPointer,
redGetSelectedTarget,
redGetTransferableValue,
Expand Down Expand Up @@ -211,7 +197,7 @@ export class VirtualEnvironment {
redCallableBatchGetPrototypeOfWhenHasNoOwnProperty,
redCallableBatchGetPrototypeOfWhenHasNoOwnPropertyDescriptor
);
foreignConnect(
redConnect(
blueGlobalThisPointer,
blueGetSelectedTarget,
blueGetTransferableValue,
Expand Down Expand Up @@ -247,14 +233,12 @@ export class VirtualEnvironment {
blueCallableBatchGetPrototypeOfWhenHasNoOwnProperty,
blueCallableBatchGetPrototypeOfWhenHasNoOwnPropertyDescriptor
);
this.blueConnector = blueConnector;
this.blueGlobalThisPointer = blueGlobalThisPointer;
this.blueGetSelectedTarget = blueGetSelectedTarget;
this.blueGetTransferableValue = blueGetTransferableValue;
this.blueCallableGetPropertyValuePointer = blueCallableGetPropertyValuePointer;
this.blueCallableLinkPointers = blueCallableLinkPointers;

this.redConnector = redConnector;
this.redGlobalThisPointer = redGlobalThisPointer;
this.redCallableGetPropertyValuePointer = redCallableGetPropertyValuePointer;
this.redCallableEvaluate = redCallableEvaluate;
Expand Down
Loading

0 comments on commit 2d0cd0e

Please sign in to comment.