Skip to content

Commit

Permalink
[chore] remove ie11 or fallback
Browse files Browse the repository at this point in the history
in addition, remove unused code
  • Loading branch information
lifeart committed Dec 24, 2023
1 parent 1070795 commit 156d243
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,13 @@ const hasDom =
self.navigator === navigator &&
typeof navigator.userAgent === 'string';

// do this to get around type issues for these values
let global = window as any;
const isChrome = hasDom
? typeof global.chrome === 'object' && !(typeof global.opera === 'object')
: false;
const isFirefox = hasDom ? /Firefox|FxiOS/u.test(navigator.userAgent) : false;

interface Counters {
adds: number;
removes: number;
}

interface OnManager {
counters: Counters;
SUPPORTS_EVENT_OPTIONS: boolean;
}

function getOnManager() {
Expand Down Expand Up @@ -75,15 +67,6 @@ if (hasDom) {
);
}

@test
'SUPPORTS_EVENT_OPTIONS is correct (private API usage)'(assert: Assert) {
let { SUPPORTS_EVENT_OPTIONS } = getOnManager();

if (isChrome || isFirefox) {
assert.strictEqual(SUPPORTS_EVENT_OPTIONS, true, 'is true in chrome and firefox');
}
}

@test
'it adds an event listener'(assert: Assert) {
let count = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/runtime/lib/dom/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class DOMOperations {
createElement(tag: string, context?: SimpleElement): SimpleElement {
let isElementInSVGNamespace: boolean, isHTMLIntegrationPoint: boolean;

if (context) {
if (context !== undefined) {
isElementInSVGNamespace = context.namespaceURI === NS_SVG || tag === 'svg';
isHTMLIntegrationPoint = !!(SVG_INTEGRATION_POINTS as Dict<number>)[context.tagName];
} else {
Expand Down
91 changes: 6 additions & 85 deletions packages/@glimmer/runtime/lib/modifiers/on.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,6 @@ import { reifyNamed } from '../vm/arguments';

const untouchableContext = buildUntouchableThis('`on` modifier');

/*
Internet Explorer 11 does not support `once` and also does not support
passing `eventOptions`. In some situations it then throws a weird script
error, like:
```
Could not complete the operation due to error 80020101
```
This flag determines, whether `{ once: true }` and thus also event options in
general are supported.
*/
const SUPPORTS_EVENT_OPTIONS = (() => {
try {
const div = document.createElement('div');
let counter = 0;
div.addEventListener('click', () => counter++, { once: true });

let event;
if (typeof Event === 'function') {
event = new Event('click');
} else {
event = document.createEvent('Event');
event.initEvent('click', true, true);
}

div.dispatchEvent(event);
div.dispatchEvent(event);

return counter === 1;
} catch (error) {
return false;
}
})();

export class OnModifierState {
public tag = createUpdatableTag();
public element: Element;
Expand Down Expand Up @@ -88,11 +53,10 @@ export class OnModifierState {
this.shouldUpdate = true;
}

let options: AddEventListenerOptions;
// we want to handle both `true` and `false` because both have a meaning:
// https://bugs.chromium.org/p/chromium/issues/detail?id=770208
if (once !== undefined || passive !== undefined || capture !== undefined) {
options = this.options = { once, passive, capture } as AddEventListenerOptions;
this.options = { once, passive, capture } as AddEventListenerOptions;
} else {
this.options = undefined;
}
Expand Down Expand Up @@ -139,13 +103,11 @@ export class OnModifierState {
);
}

let needsCustomCallback =
(SUPPORTS_EVENT_OPTIONS === false && once) /* needs manual once implementation */ ||
(import.meta.env.DEV && passive); /* needs passive enforcement */
let needsCustomCallback = import.meta.env.DEV && passive; /* needs passive enforcement */

if (this.shouldUpdate) {
if (needsCustomCallback) {
let callback = (this.callback = function (this: Element, event) {
this.callback = function (this: Element, event) {
if (import.meta.env.DEV && passive) {
event.preventDefault = () => {
throw new Error(
Expand All @@ -155,12 +117,8 @@ export class OnModifierState {
);
};
}

if (!SUPPORTS_EVENT_OPTIONS && once) {
removeEventListener(this, eventName, callback, options);
}
return userProvidedCallback.call(untouchableContext, event);
});
};
} else if (import.meta.env.DEV) {
// prevent the callback from being bound to the element
this.callback = userProvidedCallback.bind(untouchableContext);
Expand All @@ -182,24 +140,7 @@ function removeEventListener(
): void {
removes++;

if (SUPPORTS_EVENT_OPTIONS) {
// when options are supported, use them across the board
element.removeEventListener(eventName, callback, options);
} else if (options !== undefined && options.capture) {
// used only in the following case:
//
// `{ once: true | false, passive: true | false, capture: true }
//
// `once` is handled via a custom callback that removes after first
// invocation so we only care about capture here as a boolean
element.removeEventListener(eventName, callback, true);
} else {
// used only in the following cases:
//
// * where there is no options
// * `{ once: true | false, passive: true | false, capture: false }
element.removeEventListener(eventName, callback);
}
element.removeEventListener(eventName, callback, options);
}

function addEventListener(
Expand All @@ -209,25 +150,7 @@ function addEventListener(
options?: AddEventListenerOptions
): void {
adds++;

if (SUPPORTS_EVENT_OPTIONS) {
// when options are supported, use them across the board
element.addEventListener(eventName, callback, options);
} else if (options !== undefined && options.capture) {
// used only in the following case:
//
// `{ once: true | false, passive: true | false, capture: true }
//
// `once` is handled via a custom callback that removes after first
// invocation so we only care about capture here as a boolean
element.addEventListener(eventName, callback, true);
} else {
// used only in the following cases:
//
// * where there is no options
// * `{ once: true | false, passive: true | false, capture: false }
element.addEventListener(eventName, callback);
}
element.addEventListener(eventName, callback, options);
}

/**
Expand Down Expand Up @@ -317,8 +240,6 @@ function addEventListener(
@public
*/
class OnModifierManager implements InternalModifierManager<OnModifierState | null, object> {
public SUPPORTS_EVENT_OPTIONS: boolean = SUPPORTS_EVENT_OPTIONS;

getDebugName(): string {
return 'on';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/runtime/lib/vm/append.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ export class VM implements PublicVM, InternalVM {
LOCAL_LOGGER.log(`EXECUTING FROM ${this[INNER_VM].fetchRegister($pc)}`);
}

if (initialize) initialize(this);
if (initialize !== undefined) initialize(this);

let result: RichIteratorResult<null, RenderResult>;

Expand Down
19 changes: 8 additions & 11 deletions packages/@glimmer/runtime/lib/vm/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,19 @@ export class VMArgumentsImpl implements VMArguments {
bbase pbase nbase sp
*/

let named = this.named;
let namedCount = names.length;
let namedBase = stack[REGISTERS][$sp] - namedCount + 1;

named.setup(stack, namedBase, namedCount, names, atNames);
this.named.setup(stack, namedBase, namedCount, names, atNames);

let positional = this.positional;
let positionalBase = namedBase - positionalCount;

positional.setup(stack, positionalBase, positionalCount);
this.positional.setup(stack, positionalBase, positionalCount);

let blocks = this.blocks;
let blocksCount = blockNames.length;
let blocksBase = positionalBase - blocksCount * 3;

blocks.setup(stack, blocksBase, blocksCount, blockNames);
this.blocks.setup(stack, blocksBase, blocksCount, blockNames);
}

get base(): number {
Expand Down Expand Up @@ -193,7 +190,7 @@ export class PositionalArgumentsImpl implements PositionalArguments {
private get references(): readonly Reference[] {
let references = this._references;

if (!references) {
if (references === null) {
let { stack, base, length } = this;
references = this._references = stack.slice<Reference>(base, base + length);
}
Expand Down Expand Up @@ -254,7 +251,7 @@ export class NamedArgumentsImpl implements NamedArguments {
get names(): readonly string[] {
let names = this._names;

if (!names) {
if (names === null) {
names = this._names = this._atNames!.map(this.toSyntheticName);
}

Expand All @@ -264,7 +261,7 @@ export class NamedArgumentsImpl implements NamedArguments {
get atNames(): readonly string[] {
let atNames = this._atNames;

if (!atNames) {
if (atNames === null) {
atNames = this._atNames = this._names!.map(this.toAtName);
}

Expand Down Expand Up @@ -336,7 +333,7 @@ export class NamedArgumentsImpl implements NamedArguments {
private get references(): readonly Reference[] {
let references = this._references;

if (!references) {
if (references === null) {
let { base, length, stack } = this;
references = this._references = stack.slice<Reference>(base, base + length);
}
Expand Down Expand Up @@ -400,7 +397,7 @@ export class BlockArgumentsImpl implements BlockArguments {
get values(): readonly BlockValue[] {
let values = this.internalValues;

if (!values) {
if (values === null) {
let { base, length, stack } = this;
values = this.internalValues = stack.slice<BlockValue>(base, base + length * 3);
}
Expand Down
1 change: 0 additions & 1 deletion packages/@glimmer/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export { default as debugToString } from './lib/debug-to-string';
export * from './lib/dom';
export * from './lib/dom-utils';
export * from './lib/immediate';
export { default as intern } from './lib/intern';
export {
isSerializationFirstNode,
SERIALIZATION_FIRST_NODE_STRING,
Expand Down
49 changes: 0 additions & 49 deletions packages/@glimmer/util/lib/intern.ts

This file was deleted.

0 comments on commit 156d243

Please sign in to comment.