Skip to content

Commit

Permalink
bump-deps-and-fix-memory-leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Garrett committed Jan 7, 2020
1 parent e44bbb6 commit 625104e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
14 changes: 7 additions & 7 deletions packages/@ember/-internals/glimmer/lib/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { privatize as P } from '@ember/-internals/container';
import { ENV } from '@ember/-internals/environment';
import { Factory, FactoryClass, LookupOptions, Owner } from '@ember/-internals/owner';
import { Factory, FactoryClass, getOwnerById, LookupOptions, Owner } from '@ember/-internals/owner';
import { OwnedTemplateMeta } from '@ember/-internals/views';
import {
EMBER_GLIMMER_SET_COMPONENT_TEMPLATE,
Expand Down Expand Up @@ -44,7 +44,7 @@ import { CustomModifierDefinition, ModifierManagerDelegate } from './modifiers/c
import OnModifierManager from './modifiers/on';
import { mountHelper } from './syntax/mount';
import { outletHelper } from './syntax/outlet';
import { Factory as TemplateFactory, getTemplateMetaOwner, OwnedTemplate } from './template';
import { Factory as TemplateFactory, OwnedTemplate } from './template';
import { getComponentTemplate } from './utils/component-template';
import { getModifierManager } from './utils/custom-modifier-manager';
import { getManager } from './utils/managers';
Expand Down Expand Up @@ -387,7 +387,7 @@ export default class RuntimeResolver implements JitRuntimeResolver<OwnedTemplate
private _lookupHelper(_name: string, meta: OwnedTemplateMeta): Option<Helper> {
assert(
`You attempted to overwrite the built-in helper "${_name}" which is not allowed. Please rename the helper.`,
!(this.builtInHelpers[_name] && getTemplateMetaOwner(meta).hasRegistration(`helper:${_name}`))
!(this.builtInHelpers[_name] && getOwnerById(meta.ownerId).hasRegistration(`helper:${_name}`))
);

const helper = this.builtInHelpers[_name];
Expand All @@ -396,7 +396,7 @@ export default class RuntimeResolver implements JitRuntimeResolver<OwnedTemplate
}

const { moduleName } = meta;
let owner = getTemplateMetaOwner(meta);
let owner = getOwnerById(meta.ownerId);

let name = _name;
let namespace = undefined;
Expand Down Expand Up @@ -430,7 +430,7 @@ export default class RuntimeResolver implements JitRuntimeResolver<OwnedTemplate
}

private _lookupPartial(name: string, meta: OwnedTemplateMeta): PartialDefinition {
let owner = getTemplateMetaOwner(meta);
let owner = getOwnerById(meta.ownerId);
let templateFactory = lookupPartial(name, owner);
let template = templateFactory(owner);

Expand All @@ -441,7 +441,7 @@ export default class RuntimeResolver implements JitRuntimeResolver<OwnedTemplate
let builtin = this.builtInModifiers[name];

if (builtin === undefined) {
let owner = getTemplateMetaOwner(meta);
let owner = getOwnerById(meta.ownerId);
let modifier = owner.factoryFor<unknown, FactoryClass>(`modifier:${name}`);
if (modifier !== undefined) {
let managerFactory = getModifierManager<ModifierManagerDelegate<unknown>>(modifier.class);
Expand Down Expand Up @@ -472,7 +472,7 @@ export default class RuntimeResolver implements JitRuntimeResolver<OwnedTemplate
): Option<ComponentDefinition> {
let name = _name;
let namespace = undefined;
let owner = getTemplateMetaOwner(meta);
let owner = getOwnerById(meta.ownerId);
let { moduleName } = meta;

if (EMBER_MODULE_UNIFICATION) {
Expand Down
6 changes: 3 additions & 3 deletions packages/@ember/-internals/glimmer/lib/syntax.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getOwnerById } from '@ember/-internals/owner';
import { OwnedTemplateMeta } from '@ember/-internals/views';
import { assert } from '@ember/debug';
import {
Expand All @@ -11,7 +12,6 @@ import {
} from '@glimmer/interfaces';
import { EMPTY_BLOCKS, NONE, staticComponent, UNHANDLED } from '@glimmer/opcode-compiler';
import { hashToArgs } from './syntax/utils';
import { getTemplateMetaOwner } from './template';

export const experimentalMacros: any[] = [];

Expand Down Expand Up @@ -56,7 +56,7 @@ function refineBlockSyntax(

assert(
`A component or helper named "${name}" could not be found`,
getTemplateMetaOwner(context.meta.referrer as OwnedTemplateMeta).hasRegistration(
getOwnerById((context.meta.referrer as OwnedTemplateMeta).ownerId).hasRegistration(
`helper:${name}`
)
);
Expand All @@ -66,7 +66,7 @@ function refineBlockSyntax(
!(() => {
const resolver = context.resolver['inner']['resolver'];
const { moduleName } = context.meta.referrer as OwnedTemplateMeta;
const owner = getTemplateMetaOwner(context.meta.referrer as OwnedTemplateMeta);
const owner = getOwnerById((context.meta.referrer as OwnedTemplateMeta).ownerId);
if (name === 'component' || resolver['builtInHelpers'][name]) {
return true;
}
Expand Down
14 changes: 0 additions & 14 deletions packages/@ember/-internals/glimmer/lib/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ import { templateFactory } from '@glimmer/opcode-compiler';
export type StaticTemplate = SerializedTemplateWithLazyBlock<StaticTemplateMeta>;
export type OwnedTemplate = Template<OwnedTemplateMeta>;

const OWNER_ID_TO_HANDLE = new Map<string, {}>();
const HANDLE_TO_OWNER = new WeakMap<{}, Owner>();

export function getTemplateMetaOwner({ ownerId }: OwnedTemplateMeta): Owner {
let handle = OWNER_ID_TO_HANDLE.get(ownerId)!;
return HANDLE_TO_OWNER.get(handle)!;
}

export function isTemplateFactory(template: OwnedTemplate | Factory): template is Factory {
return typeof template === 'function';
}
Expand Down Expand Up @@ -42,12 +34,6 @@ export default function template(json: StaticTemplate): Factory {
let result = cache.get(owner);
let ownerId = guidFor(owner);

if (!OWNER_ID_TO_HANDLE.has(ownerId)) {
let handle = {};
OWNER_ID_TO_HANDLE.set(ownerId, handle);
HANDLE_TO_OWNER.set(handle, owner);
}

if (result === undefined) {
counters.cacheMiss++;
result = glimmerFactory.create(Object.assign({ ownerId }, meta));
Expand Down
9 changes: 9 additions & 0 deletions packages/@ember/-internals/owner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface Owner {
}

import { symbol } from '@ember/-internals/utils';
import { assert } from '@ember/debug';

export const OWNER: unique symbol = symbol('OWNER') as any;

Expand Down Expand Up @@ -104,3 +105,11 @@ export function getOwner(object: any): Owner {
export function setOwner(object: any, owner: Owner): void {
object[OWNER] = owner;
}

export const OWNER_MAP = new Map<string, Owner>();

export function getOwnerById(ownerId: string): Owner {
assert('Attempted to lookup an owner that no longer exists', OWNER_MAP.has(ownerId));

return OWNER_MAP.get(ownerId)!;
}
14 changes: 14 additions & 0 deletions packages/@ember/-internals/runtime/lib/mixins/container_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { schedule, join } from '@ember/runloop';
@module ember
*/
import { Mixin } from '@ember/-internals/metal';
import { guidFor } from '@ember/-internals/utils';
import { OWNER_MAP } from '@ember/-internals/owner';

/**
ContainerProxyMixin is used to provide public access to specific
Expand All @@ -12,6 +14,18 @@ import { Mixin } from '@ember/-internals/metal';
@private
*/
let containerProxyMixin = {
init() {
this._super(...arguments);

OWNER_MAP.set(guidFor(this), this);
},

willDestroy() {
this._super();

OWNER_MAP.delete(guidFor(this));
},

/**
The container stores state.
Expand Down
3 changes: 1 addition & 2 deletions packages/@ember/engine/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
RegistryProxyMixin,
RSVP,
} from '@ember/-internals/runtime';
import { OWNER_MAP } from '@ember/-internals/owner';
import { assert } from '@ember/debug';
import EmberError from '@ember/error';
import { Registry, privatize as P } from '@ember/-internals/container';
Expand Down Expand Up @@ -37,8 +38,6 @@ const EngineInstance = EmberObject.extend(RegistryProxyMixin, ContainerProxyMixi
init() {
this._super(...arguments);

guidFor(this);

let base = this.base;

if (!base) {
Expand Down

0 comments on commit 625104e

Please sign in to comment.