From a49084473bb4961c6040aaf0418a1f701b38361e Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 22 Oct 2021 16:29:24 -0500 Subject: [PATCH] feat: ResizeObserver --- src/lib/sandbox/read-main-interfaces.ts | 5 +- src/lib/types.ts | 5 +- src/lib/utils.ts | 4 + tests/index.html | 1 + tests/platform/mutation-observer/index.html | 2 +- .../mutation-observer.spec.ts | 2 +- tests/platform/resize-observer/index.html | 139 ++++++++++++++++++ .../resize-observer/resize-observer.spec.ts | 36 +++++ 8 files changed, 188 insertions(+), 6 deletions(-) create mode 100644 tests/platform/resize-observer/index.html create mode 100644 tests/platform/resize-observer/resize-observer.spec.ts diff --git a/src/lib/sandbox/read-main-interfaces.ts b/src/lib/sandbox/read-main-interfaces.ts index f971d727..0fa651c5 100644 --- a/src/lib/sandbox/read-main-interfaces.ts +++ b/src/lib/sandbox/read-main-interfaces.ts @@ -1,4 +1,4 @@ -import { debug, getConstructorName, isValidMemberName, logMain } from '../utils'; +import { debug, getConstructorName, isValidMemberName, logMain, noop } from '../utils'; import { InitWebWorkerData, InterfaceInfo, InterfaceType, MainWindow } from '../types'; export const readMainInterfaces = (win: MainWindow) => { @@ -24,9 +24,10 @@ export const readMainInterfaces = (win: MainWindow) => { [InterfaceType.CanvasRenderingContext2D, canvasRenderingContext2D], [InterfaceType.History, win.history], [InterfaceType.Location, win.location], - [InterfaceType.MutationObserver, new MutationObserver(() => {})], + [InterfaceType.MutationObserver, new MutationObserver(noop)], [InterfaceType.NamedNodeMap, inputElm.attributes], [InterfaceType.NodeList, inputElm.childNodes], + [InterfaceType.ResizeObserver, new ResizeObserver(noop)], [InterfaceType.Screen, win.screen], [InterfaceType.Storage, win.localStorage], [InterfaceType.TextNode, docImpl.createTextNode('')], diff --git a/src/lib/types.ts b/src/lib/types.ts index 8e4671a9..27f4f32e 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -151,8 +151,9 @@ export const enum InterfaceType { MutationObserver = 20, NodeList = 21, NamedNodeMap = 22, - Screen = 23, - Storage = 24, + ResizeObserver = 23, + Screen = 24, + Storage = 25, } export const enum PlatformInstanceId { diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 2ecff57e..d2981ca0 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -15,6 +15,8 @@ export const toLower = (str: string) => str.toLowerCase(); export const toUpper = (str: string) => str.toUpperCase(); +export const noop = () => {}; + export const logMain = (msg: string) => { if (debug) { console.debug.apply(console, [ @@ -158,6 +160,8 @@ const logTargetProp = (target: any, accessType: 'Get' | 'Set' | 'Call', applyPat n = 'documentTypeNode.'; } else if (target[InterfaceTypeKey] === InterfaceType.MutationObserver) { n = 'mutationObserver.'; + } else if (target[InterfaceTypeKey] === InterfaceType.ResizeObserver) { + n = 'resizeObserver.'; } else if (target[InterfaceTypeKey] <= InterfaceType.DocumentFragmentNode) { n = 'node.'; } else { diff --git a/tests/index.html b/tests/index.html index 415684b8..415a295c 100644 --- a/tests/index.html +++ b/tests/index.html @@ -89,6 +89,7 @@

Platform Tests

  • MutationObserver
  • Navigator
  • Node
  • +
  • ResizeObserver
  • Script
  • Storage
  • Style
  • diff --git a/tests/platform/mutation-observer/index.html b/tests/platform/mutation-observer/index.html index 1904784d..7048bd63 100644 --- a/tests/platform/mutation-observer/index.html +++ b/tests/platform/mutation-observer/index.html @@ -67,7 +67,7 @@ -

    Mutation Observer

    +

    MutationObserver