Skip to content

Commit

Permalink
feat: @W-12357687 make alive iframe a revoked proxy (#410)
Browse files Browse the repository at this point in the history
* chore: cleanup var names

* feat: @W-12357687 make alive iframe a revoked proxy
  • Loading branch information
jdalton authored Jan 12, 2023
1 parent 6e870e6 commit f953fe9
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 120 deletions.
16 changes: 8 additions & 8 deletions packages/near-membrane-base/src/__tests__/intrinsics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ describe('assignFilteredGlobalDescriptorsFromPropertyDescriptorMap', () => {
accum[key] = globalThis[key];
return accum;
}, {});
const descMap = assignFilteredGlobalDescriptorsFromPropertyDescriptorMap(
const descs = assignFilteredGlobalDescriptorsFromPropertyDescriptorMap(
{},
Object.getOwnPropertyDescriptors(shape)
);
for (const key of ESGlobalKeys) {
expect(key in descMap).toBe(false);
expect(key in descs).toBe(false);
}
});
it('ignores Reflective ES intrinsics', () => {
Expand All @@ -152,12 +152,12 @@ describe('assignFilteredGlobalDescriptorsFromPropertyDescriptorMap', () => {
accum[key] = globalThis[key];
return accum;
}, {});
const descMap = assignFilteredGlobalDescriptorsFromPropertyDescriptorMap(
const descs = assignFilteredGlobalDescriptorsFromPropertyDescriptorMap(
{},
Object.getOwnPropertyDescriptors(shape)
);
for (const key of ReflectiveIntrinsicObjectNames) {
expect(key in descMap).toBe(false);
expect(key in descs).toBe(false);
}
});
it('includes Remapped ES intrinsics', () => {
Expand All @@ -169,20 +169,20 @@ describe('assignFilteredGlobalDescriptorsFromPropertyDescriptorMap', () => {
accum[key] = globalThis[key];
return accum;
}, {});
const descMap = assignFilteredGlobalDescriptorsFromPropertyDescriptorMap(
const descs = assignFilteredGlobalDescriptorsFromPropertyDescriptorMap(
{},
Object.getOwnPropertyDescriptors(shape)
);
for (const key of RemappedIntrinsicObjectNames) {
expect(descMap[key]).toBeDefined();
expect(descs[key]).toBeDefined();
}
});
it('should create a descriptor for non-ES built-ins', () => {
// Ignoring "Property 'assertions' does not exist on type '{...}'."
// @ts-ignore
expect.assertions(1);

const descMap = assignFilteredGlobalDescriptorsFromPropertyDescriptorMap(
const descs = assignFilteredGlobalDescriptorsFromPropertyDescriptorMap(
{},
Object.getOwnPropertyDescriptors({
Foo: 1,
Expand All @@ -191,7 +191,7 @@ describe('assignFilteredGlobalDescriptorsFromPropertyDescriptorMap', () => {
// Ignoring
// "Property 'toMatchObject' does not exist on type 'Matchers<PropertyDescriptor>'."
// @ts-ignore
expect(descMap.Foo).toMatchObject({
expect(descs.Foo).toMatchObject({
configurable: true,
enumerable: true,
value: 1,
Expand Down
12 changes: 7 additions & 5 deletions packages/near-membrane-base/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ export class VirtualEnvironment {
// prettier-ignore
const {
blueConnector,
redConnector,
distortionCallback,
instrumentation,
liveTargetCallback,
redConnector,
revokedProxyCallback,
// eslint-disable-next-line prefer-object-spread
} = ObjectAssign({ __proto__: null }, options);
let blueHooks: Parameters<HooksCallback>;
Expand All @@ -77,6 +78,7 @@ export class VirtualEnvironment {
distortionCallback,
instrumentation,
liveTargetCallback,
revokedProxyCallback,
}
);
const {
Expand Down Expand Up @@ -300,17 +302,17 @@ export class VirtualEnvironment {
}
}

remapProperties(target: ProxyTarget, unsafeBlueDescMap: PropertyDescriptorMap) {
remapProperties(target: ProxyTarget, unsafeBlueDescs: PropertyDescriptorMap) {
if ((typeof target === 'object' && target !== null) || typeof target === 'function') {
const targetPointer = this.blueGetTransferableValue(target) as Pointer;
const ownKeys = ReflectOwnKeys(unsafeBlueDescMap);
const ownKeys = ReflectOwnKeys(unsafeBlueDescs);
const { length } = ownKeys;
const args = new ArrayCtor(1 + length * 7) as Parameters<CallableDefineProperties>;
args[0] = targetPointer;
for (let i = 0, j = 1; i < length; i += 1, j += 7) {
const ownKey = ownKeys[i];
const unsafeBlueDesc = (unsafeBlueDescMap as any)[ownKey];
// Avoid poisoning by only installing own properties from unsafeBlueDescMap.
const unsafeBlueDesc = (unsafeBlueDescs as any)[ownKey];
// Avoid poisoning by only installing own properties from unsafeBlueDescs.
// We don't use a toSafeDescriptor() style helper since that mutates
// the unsafeBlueDesc.
// eslint-disable-next-line prefer-object-spread
Expand Down
6 changes: 3 additions & 3 deletions packages/near-membrane-base/src/intrinsics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const ESGlobalsAndReflectiveIntrinsicObjectNames = toSafeArray([

export function assignFilteredGlobalDescriptorsFromPropertyDescriptorMap<
T extends PropertyDescriptorMap
>(descMap: T, source: PropertyDescriptorMap): T {
>(descs: T, source: PropertyDescriptorMap): T {
const ownKeys = ReflectOwnKeys(source);
for (let i = 0, { length } = ownKeys; i < length; i += 1) {
const ownKey = ownKeys[i];
Expand All @@ -136,11 +136,11 @@ export function assignFilteredGlobalDescriptorsFromPropertyDescriptorMap<
// unsafeDesc. We don't use a toSafeDescriptor() style helper
// since that mutates the unsafeBlueDesc.
// eslint-disable-next-line prefer-object-spread
(descMap as any)[ownKey] = ObjectAssign({ __proto__: null }, unsafeDesc);
(descs as any)[ownKey] = ObjectAssign({ __proto__: null }, unsafeDesc);
}
}
}
return descMap;
return descs;
}

export function getFilteredGlobalOwnKeys(source: object): PropertyKey[] {
Expand Down
Loading

0 comments on commit f953fe9

Please sign in to comment.