diff --git a/ember_debug/adapters/web-extension.js b/ember_debug/adapters/web-extension.js index fb98e2a882..a4d1ef30a3 100644 --- a/ember_debug/adapters/web-extension.js +++ b/ember_debug/adapters/web-extension.js @@ -1,7 +1,7 @@ import BasicAdapter from './basic'; import { typeOf } from 'ember-debug/utils/type-check'; -import Ember from 'ember-debug/utils/ember'; +import { ember } from 'ember-debug/utils/ember'; import { run } from 'ember-debug/utils/ember/runloop'; const { isArray } = Array; @@ -105,7 +105,7 @@ export default class extends BasicAdapter { // adapter later. See GH #1114. const HAS_ARRAY_PROTOTYPE_EXTENSIONS = (() => { try { - return Ember.ENV.EXTEND_PROTOTYPES.Array === true; + return ember.env.EXTEND_PROTOTYPES.Array === true; } catch (e) { return false; } diff --git a/ember_debug/deprecation-debug.js b/ember_debug/deprecation-debug.js index c331297c69..3cfbb9dca9 100644 --- a/ember_debug/deprecation-debug.js +++ b/ember_debug/deprecation-debug.js @@ -1,7 +1,7 @@ import DebugPort from './debug-port'; import SourceMap from 'ember-debug/libs/source-map'; -import { registerDeprecationHandler } from 'ember-debug/utils/ember/debug'; +import { debug } from 'ember-debug/utils/ember'; import { guidFor } from 'ember-debug/utils/ember/object/internals'; import { cancel, debounce } from 'ember-debug/utils/ember/runloop'; @@ -194,7 +194,7 @@ export default class extends DebugPort { } handleDeprecations() { - registerDeprecationHandler((message, options, next) => { + debug.registerDeprecationHandler((message, options, next) => { if (!this.adapter) { next(message, options); return; diff --git a/ember_debug/general-debug.js b/ember_debug/general-debug.js index 230faea385..fff1dc0450 100644 --- a/ember_debug/general-debug.js +++ b/ember_debug/general-debug.js @@ -1,7 +1,7 @@ /* eslint no-empty:0 */ import DebugPort from './debug-port'; -import Ember from 'ember-debug/utils/ember'; +import { utils } from 'ember-debug/utils/ember'; /** * Class that handles gathering general information of the inspected app. @@ -87,9 +87,7 @@ export default class extends DebugPort { * the info tab. */ getLibraries() { - this.sendMessage('libraries', { - libraries: Ember.libraries?._registry, - }); + this.sendMessage('libraries', { libraries: utils.libraries._registry }); }, getEmberCliConfig() { diff --git a/ember_debug/libs/promise-assembler.js b/ember_debug/libs/promise-assembler.js index 9c97fd18a5..19a6f176af 100644 --- a/ember_debug/libs/promise-assembler.js +++ b/ember_debug/libs/promise-assembler.js @@ -6,7 +6,7 @@ */ import Promise from 'ember-debug/models/promise'; -import RSVP from 'ember-debug/utils/rsvp'; +import { classes } from 'ember-debug/utils/ember'; import BaseObject from 'ember-debug/utils/base-object'; import Evented from 'ember-debug/utils/evented'; @@ -15,7 +15,7 @@ class PromiseAssembler extends BaseObject { isStarted = false; static { - this.prototype.RSVP = RSVP; + this.prototype.RSVP = classes.RSVP; } constructor(data) { diff --git a/ember_debug/libs/render-tree.js b/ember_debug/libs/render-tree.js index 9cb6ce0ea7..5df4f0d173 100644 --- a/ember_debug/libs/render-tree.js +++ b/ember_debug/libs/render-tree.js @@ -1,15 +1,14 @@ -import captureRenderTree from './capture-render-tree'; import { guidFor } from 'ember-debug/utils/ember/object/internals'; import { EmberLoader, emberSafeRequire } from 'ember-debug/utils/ember/loader'; +import { debug, glimmer, ember } from 'ember-debug/utils/ember'; import { inspect } from 'ember-debug/utils/type-check'; import { isInVersionSpecifier } from 'ember-debug/utils/version'; -import { VERSION } from 'ember-debug/utils/ember'; class InElementSupportProvider { constructor(owner) { this.nodeMap = new Map(); this.remoteRoots = []; - this.runtime = this.require('@glimmer/runtime'); + this.runtime = this.require('@glimmer/runtime') || glimmer.runtime; this.reference = this.require('@glimmer/reference'); try { this.Wormhole = requireModule('ember-wormhole/components/ember-wormhole'); @@ -30,7 +29,8 @@ class InElementSupportProvider { this.registerDestructor = emberSafeRequire('@glimmer/destroyable')?.registerDestructor || emberSafeRequire('@ember/destroyable')?.registerDestructor || - emberSafeRequire('@ember/runtime')?.registerDestructor; + emberSafeRequire('@ember/runtime')?.registerDestructor || + glimmer.runtime.registerDestructor; this.debugRenderTree = owner.lookup('renderer:-dom')?.debugRenderTree || @@ -52,11 +52,11 @@ class InElementSupportProvider { const componentStack = []; const enableModifierSupport = - isInVersionSpecifier('>3.28.0', VERSION) && - !isInVersionSpecifier('>5.9.0', VERSION); + isInVersionSpecifier('>3.28.0', ember.VERSION) && + !isInVersionSpecifier('>5.9.0', ember.VERSION); const hasModifierAndInElementSupport = isInVersionSpecifier( '>5.9.0', - VERSION + ember.VERSION ); function createRef(value) { @@ -353,7 +353,7 @@ export default class RenderTree { build() { this._reset(); - this.tree = captureRenderTree(this.owner); + this.tree = debug.captureRenderTree(this.owner); let serialized = this._serializeRenderNodes(this.tree); this._releaseStaleObjects(); diff --git a/ember_debug/models/profile-manager.js b/ember_debug/models/profile-manager.js index 1e737a35fb..bbf09ae9e8 100644 --- a/ember_debug/models/profile-manager.js +++ b/ember_debug/models/profile-manager.js @@ -1,5 +1,5 @@ import ProfileNode from './profile-node'; -import Ember from 'ember-debug/utils/ember'; +import { ember } from 'ember-debug/utils/ember'; import { compareVersion } from 'ember-debug/utils/version'; import { later, scheduleOnce, cancel } from 'ember-debug/utils/ember/runloop'; @@ -75,7 +75,7 @@ export default class ProfileManager { this.stylesheet = insertStylesheet(); // keep track of all the active highlights this.highlights = []; - this.isHighlightEnabled = compareVersion(Ember?.VERSION, '3.20.0') !== -1; + this.isHighlightEnabled = compareVersion(ember?.VERSION, '3.20.0') !== -1; } began(timestamp, payload, now) { diff --git a/ember_debug/object-inspector.js b/ember_debug/object-inspector.js index 729829bdd4..204aeb371b 100644 --- a/ember_debug/object-inspector.js +++ b/ember_debug/object-inspector.js @@ -9,14 +9,11 @@ import { } from 'ember-debug/utils/type-check'; import { compareVersion } from 'ember-debug/utils/version'; import { - EmberObject, - meta as emberMeta, - VERSION, - CoreObject, - ObjectProxy, - ArrayProxy, - Service, - Component, + classes, + debug, + object, + ember, + glimmer, } from 'ember-debug/utils/ember'; import { cacheFor, guidFor } from 'ember-debug/utils/ember/object/internals'; import { _backburner, join } from 'ember-debug/utils/ember/runloop'; @@ -24,19 +21,15 @@ import emberNames from './utils/ember-object-names'; import getObjectName from './utils/get-object-name'; import { EmberLoader } from 'ember-debug/utils/ember/loader'; -const GlimmerComponent = (() => { - try { - return EmberLoader.require('@glimmer/component').default; - } catch (e) { - // ignore, return undefined - } -})(); +const { CoreObject, ObjectProxy } = classes; +const { VERSION } = ember; +const { meta: emberMeta } = object; let tagValue, tagValidate, track, tagForProperty; try { // Try to load the most recent library - let GlimmerValidator = EmberLoader.require('@glimmer/validator'); + let GlimmerValidator = glimmer.validator; tagValue = GlimmerValidator.value || GlimmerValidator.valueForTag; tagValidate = GlimmerValidator.validate || GlimmerValidator.validateTag; @@ -83,11 +76,9 @@ try { } try { - let metal = EmberLoader.require('@ember/-internals/metal'); - - tagForProperty = metal.tagForProperty; + tagForProperty = debug.tagForProperty; // If track was not already loaded, use metal's version (the previous version) - track = track || metal.track; + track = track || debug.track; } catch (e) { // ignore } @@ -122,7 +113,7 @@ function inspectValue(object, key, computedValue) { return { type: `type-${typeOf(value)}`, inspect: inspect(value) }; } - if (value instanceof EmberObject) { + if (value instanceof classes.EmberObject) { return { type: 'type-ember-object', inspect: value.toString() }; } else if (isComputed(object, key)) { string = ''; @@ -136,18 +127,6 @@ function inspectValue(object, key, computedValue) { } } -function isMandatorySetter(descriptor) { - if ( - descriptor.set && - Function.prototype.toString - .call(descriptor.set) - .includes('You attempted to update') - ) { - return true; - } - return false; -} - function getTagTrackedTags(tag, ownTag, level = 0) { const props = []; // do not include tracked properties from dependencies @@ -276,8 +255,7 @@ export default class extends DebugPort { const tracked = (this.trackedTags[objectId] = this.trackedTags[objectId] || {}); - const desc = Object.getOwnPropertyDescriptor(object, item.name); - const isSetter = desc && isMandatorySetter(desc); + const isSetter = debug.isMandatorySetter(object, item.name); if (HAS_GLIMMER_TRACKING && item.canTrack && !isSetter) { let tagInfo = tracked[item.name] || { @@ -461,7 +439,7 @@ export default class extends DebugPort { canSend(val) { return ( val && - (val instanceof EmberObject || + (val instanceof classes.EmberObject || val instanceof Object || typeOf(val) === 'object' || typeOf(val) === 'array') @@ -518,7 +496,7 @@ export default class extends DebugPort { value = value.stack; } let args = [value]; - if (value instanceof EmberObject) { + if (value instanceof classes.EmberObject) { args.unshift(inspect(value)); } this.adapter.log('Ember Inspector ($E): ', ...args); @@ -704,7 +682,7 @@ export default class extends DebugPort { } if ( - object instanceof ArrayProxy && + object instanceof classes.ArrayProxy && object.content && !object._showProxyDetails ) { @@ -910,7 +888,7 @@ function addProperties(properties, hash) { continue; } - let options = { isMandatorySetter: isMandatorySetter(desc) }; + let options = { isMandatorySetter: debug.isMandatorySetter(desc) }; if (typeof hash[prop] === 'object' && hash[prop] !== null) { options.isService = @@ -923,7 +901,7 @@ function addProperties(properties, hash) { } if (!options.isService) { - options.isService = desc.value instanceof Service; + options.isService = desc.value instanceof classes.Service; } } if (options.isService) { @@ -933,9 +911,9 @@ function addProperties(properties, hash) { if (isComputed(hash, prop)) { options.isComputed = true; - options.dependentKeys = (desc._dependentKeys || []).map((key) => - key.toString() - ); + options.dependentKeys = (desc._dependentKeys || []).map((key) => ({ + name: key.toString(), + })); if (typeof desc.get === 'function') { options.code = Function.prototype.toString.call(desc.get); @@ -1255,7 +1233,7 @@ function getDebugInfo(object) { let debugInfo = null; let objectDebugInfo = object._debugInfo; if (objectDebugInfo && typeof objectDebugInfo === 'function') { - if (object instanceof ObjectProxy && object.content) { + if (object instanceof classes.ObjectProxy && object.content) { object = object.content; } debugInfo = objectDebugInfo.call(object); @@ -1268,7 +1246,7 @@ function getDebugInfo(object) { skipProperties.push('isDestroyed', 'isDestroying', 'container'); // 'currentState' and 'state' are un-observable private properties. // The rest are skipped to reduce noise in the inspector. - if (Component && object instanceof Component) { + if (classes.EmberComponent && object instanceof classes.EmberComponent) { skipProperties.push( 'currentState', 'state', @@ -1284,7 +1262,10 @@ function getDebugInfo(object) { 'element', 'targetObject' ); - } else if (GlimmerComponent && object instanceof GlimmerComponent) { + } else if ( + classes.GlimmerComponent && + object instanceof classes.GlimmerComponent + ) { // These properties don't really exist on Glimmer Components, but // reading their values trigger a development mode assertion. The // more correct long term fix is to make getters lazy (shows "..." @@ -1303,7 +1284,10 @@ function calculateCP(object, item, errorsForObject) { const property = item.name; delete errorsForObject[property]; try { - if (object instanceof ArrayProxy && property == parseInt(property)) { + if ( + object instanceof classes.ArrayProxy && + property == parseInt(property) + ) { return object.objectAt(property); } return item.isGetter || property.includes?.('.') diff --git a/ember_debug/promise-debug.js b/ember_debug/promise-debug.js index 5e3fe77404..38d9fb9e68 100644 --- a/ember_debug/promise-debug.js +++ b/ember_debug/promise-debug.js @@ -1,7 +1,7 @@ import DebugPort from './debug-port'; import PromiseAssembler from 'ember-debug/libs/promise-assembler'; import { debounce } from 'ember-debug/utils/ember/runloop'; -import RSVP from 'ember-debug/utils/rsvp'; +import { classes } from 'ember-debug/utils/ember'; export default class extends DebugPort { get objectInspector() { @@ -101,7 +101,7 @@ export default class extends DebugPort { } setInstrumentWithStack() { - RSVP.configure('instrument-with-stack', this.instrumentWithStack); + classes.RSVP.configure('instrument-with-stack', this.instrumentWithStack); this.sendInstrumentWithStack(); } diff --git a/ember_debug/render-debug.js b/ember_debug/render-debug.js index 955e300b1f..e5a7f2eeb8 100644 --- a/ember_debug/render-debug.js +++ b/ember_debug/render-debug.js @@ -1,8 +1,8 @@ import DebugPort from './debug-port'; import ProfileManager from './models/profile-manager'; -import { subscribe } from 'ember-debug/utils/ember/instrumentation'; import { _backburner } from 'ember-debug/utils/ember/runloop'; +import { instrumentation } from 'ember-debug/utils/ember'; import bound from 'ember-debug/utils/bound-method'; // Initial setup, that has to occur before the EmberObject init for some reason @@ -78,7 +78,7 @@ export default class extends DebugPort { * @private */ function _subscribeToRenderEvents() { - subscribe('render', { + instrumentation.subscribe('render', { before(name, timestamp, payload) { const info = { type: 'began', diff --git a/ember_debug/route-debug.js b/ember_debug/route-debug.js index 3020e8d1a8..b108bd4a03 100644 --- a/ember_debug/route-debug.js +++ b/ember_debug/route-debug.js @@ -1,9 +1,9 @@ /* eslint-disable ember/no-private-routing-service */ import DebugPort from './debug-port'; import { compareVersion } from 'ember-debug/utils/version'; -import { VERSION } from 'ember-debug/utils/ember'; import classify from 'ember-debug/utils/classify'; import dasherize from 'ember-debug/utils/dasherize'; +import { ember } from 'ember-debug/utils/ember'; import { _backburner, later } from 'ember-debug/utils/ember/runloop'; import bound from 'ember-debug/utils/bound-method'; @@ -201,7 +201,7 @@ function buildSubTree(routeTree, route) { // 3.9.0 removed intimate APIs from router // https://github.com/emberjs/ember.js/pull/17843 // https://deprecations.emberjs.com/v3.x/#toc_remove-handler-infos - if (compareVersion(VERSION, '3.9.0') !== -1) { + if (compareVersion(ember.VERSION, '3.9.0') !== -1) { // Ember >= 3.9.0 routeHandler = routerLib.getRoute(handler); } else { diff --git a/ember_debug/utils/ember-object-names.js b/ember_debug/utils/ember-object-names.js index 6a7e77d0e2..cc66fe5579 100644 --- a/ember_debug/utils/ember-object-names.js +++ b/ember_debug/utils/ember-object-names.js @@ -1,52 +1,31 @@ -import { compareVersion } from 'ember-debug/utils/version'; -import { emberSafeRequire } from 'ember-debug/utils/ember/loader'; -import { - VERSION, - ActionHandler, - ControllerMixin, - CoreObject, - MutableEnumerable, - NativeArray, - MutableArray, - Component, - Evented, - PromiseProxyMixin, - EmberObject, - Observable, -} from 'ember-debug/utils/ember'; +import { classes, Views } from 'ember-debug/utils/ember'; /** * Add Known Ember Mixins and Classes so we can label them correctly in the inspector */ const emberNames = new Map([ - [Evented, 'Evented Mixin'], - [PromiseProxyMixin, 'PromiseProxy Mixin'], - [MutableArray, 'MutableArray Mixin'], - [MutableEnumerable, 'MutableEnumerable Mixin'], - [NativeArray, 'NativeArray Mixin'], - [Observable, 'Observable Mixin'], - [ControllerMixin, 'Controller Mixin'], - [ActionHandler, 'ActionHandler Mixin'], - [CoreObject, 'CoreObject'], - [EmberObject, 'EmberObject'], - [Component, 'Component'], + [classes.Evented, 'Evented Mixin'], + [classes.PromiseProxyMixin, 'PromiseProxy Mixin'], + [classes.MutableArray, 'MutableArray Mixin'], + [classes.MutableEnumerable, 'MutableEnumerable Mixin'], + [classes.NativeArray, 'NativeArray Mixin'], + [classes.Observable, 'Observable Mixin'], + [classes.ControllerMixin, 'Controller Mixin'], + [classes.ActionHandler, 'ActionHandler Mixin'], + [classes.CoreObject, 'CoreObject'], + [classes.EmberObject, 'EmberObject'], + [classes.GlimmerComponent, 'Component'], + [classes.EmberComponent, 'Component'], ]); -if (compareVersion(VERSION, '3.27.0') === -1) { - const TargetActionSupport = emberSafeRequire( - '@ember/-internals/runtime' - )?.TargetActionSupport; - emberNames.set(TargetActionSupport, 'TargetActionSupport Mixin'); -} - try { - const Views = emberSafeRequire('@ember/-internals/views') || {}; emberNames.set(Views.ViewStateSupport, 'ViewStateSupport Mixin'); emberNames.set(Views.ViewMixin, 'View Mixin'); emberNames.set(Views.ActionSupport, 'ActionSupport Mixin'); emberNames.set(Views.ClassNamesSupport, 'ClassNamesSupport Mixin'); emberNames.set(Views.ChildViewsSupport, 'ChildViewsSupport Mixin'); emberNames.set(Views.ViewStateSupport, 'ViewStateSupport Mixin'); + emberNames.set(classes.TargetActionSupport, 'TargetActionSupport Mixin'); // this one is not a Mixin, but an .extend({}), which results in a class emberNames.set(Views.CoreView, 'CoreView'); } catch (e) { diff --git a/ember_debug/utils/ember.js b/ember_debug/utils/ember.js index 947c185f5d..894ff80b3c 100644 --- a/ember_debug/utils/ember.js +++ b/ember_debug/utils/ember.js @@ -9,38 +9,54 @@ try { } let { + libraries, ArrayProxy, - Namespace, + ObjectProxy, ActionHandler, + Namespace, + _captureRenderTree: captureRenderTree, ControllerMixin, CoreObject, Application, MutableArray, MutableEnumerable, NativeArray, - Component, + Component: EmberComponent, Observable, Evented, - PromiseProxyMixin, Service, + PromiseProxyMixin, Object: EmberObject, - ObjectProxy, VERSION, - ComputedProperty, meta, get, set, - computed, - _captureRenderTree: captureRenderTree, + runloop: runloop_, + cacheFor, + guidFor, + getOwner, + isTrackedProperty, + isCachedProperty, + isMandatorySetter, + isTesting, + inspect, + Debug: { registerDeprecationHandler }, + TargetActionSupport, + GlimmerComponent, + Instrumentation: instrumentation_, + RSVP, + ENV: ENV_, } = Ember || {}; -let getEnv = () => Ember.ENV; +let metal = emberSafeRequire('@ember/-internals/metal'); +runloop_ = Ember?.runloop || Ember?.run; +runloop_.run = Ember?.run || runloop_.run; -if (!Ember) { - captureRenderTree = emberSafeRequire('@ember/debug')?.captureRenderTree; - getEnv = emberSafeRequire('@ember/-internals/environment')?.getENV; - ArrayProxy = emberSafeRequire('@ember/array/proxy')?.default; +if (metal) { + ActionHandler = emberSafeRequire('@ember/-internals/runtime')?.ActionHandler; ObjectProxy = emberSafeRequire('@ember/object/proxy')?.default; + ArrayProxy = emberSafeRequire('@ember/array/proxy')?.default; + libraries = emberSafeRequire('@ember/-internals/metal')?.libraries; MutableArray = emberSafeRequire('@ember/array/mutable')?.default; Namespace = emberSafeRequire('@ember/application/namespace')?.default; MutableEnumerable = emberSafeRequire('@ember/enumerable/mutable')?.default; @@ -48,48 +64,185 @@ if (!Ember) { ControllerMixin = emberSafeRequire('@ember/controller')?.ControllerMixin; CoreObject = emberSafeRequire('@ember/object/core')?.default; Application = emberSafeRequire('@ember/application')?.default; - Component = emberSafeRequire('@ember/component')?.default; + EmberComponent = emberSafeRequire('@ember/component')?.default; + GlimmerComponent = emberSafeRequire('@glimmer/component')?.default; Observable = emberSafeRequire('@ember/object/observable')?.default; Evented = emberSafeRequire('@ember/object/evented')?.default; + Service = emberSafeRequire('@ember/service')?.default; PromiseProxyMixin = emberSafeRequire( '@ember/object/promise-proxy-mixin' )?.default; - Service = emberSafeRequire('@ember/service')?.default; EmberObject = emberSafeRequire('@ember/object')?.default; VERSION = emberSafeRequire('ember/version')?.default; - ComputedProperty = emberSafeRequire( - '@ember/-internals/metal' - )?.ComputedProperty; + metal = emberSafeRequire('@ember/-internals/metal'); + TargetActionSupport = emberSafeRequire( + '@ember/-internals/runtime' + )?.TargetActionSupport; meta = emberSafeRequire('@ember/-internals/meta')?.meta; set = emberSafeRequire('@ember/object')?.set; get = emberSafeRequire('@ember/object')?.get; + runloop_ = emberSafeRequire('@ember/runloop'); + cacheFor = emberSafeRequire('@ember/object/internals')?.cacheFor; + guidFor = emberSafeRequire('@ember/object/internals')?.guidFor; + getOwner = emberSafeRequire('@ember/owner')?.getOwner; + inspect = + emberSafeRequire('@ember/debug')?.inspect || + emberSafeRequire('@ember/-internals/utils')?.inspect; + registerDeprecationHandler = + emberSafeRequire('@ember/debug')?.registerDeprecationHandler; + instrumentation_ = emberSafeRequire('@ember/instrumentation'); + RSVP = emberSafeRequire('rsvp'); + ENV_ = emberSafeRequire('@ember/-internals/environment')?.ENV; +} + +const { + ComputedProperty, + isComputed, + descriptorForProperty, + descriptorForDecorator, + tagForProperty, + track, +} = metal || {}; + +const { _backburner, cancel, debounce, join, later, scheduleOnce, run } = + runloop_ || {}; +const { + ViewStateSupport, + ViewMixin, + ActionSupport, + ClassNamesSupport, + ChildViewsSupport, + CoreView, +} = emberSafeRequire('@ember/-internals/views') || Ember || {}; + +const GlimmerValidator_ = emberSafeRequire('@glimmer/validator') || {}; +const GlimmerRuntime_ = emberSafeRequire('@glimmer/runtime') || {}; + +export function assignEmberInfo(data) { + Object.assign(ember, data); + Object.assign(utils, data.utils); + Object.assign(runloop, data.runloop); + Object.assign(object, data.object); + Object.assign(debug, data.debug); + Object.assign(classes, data.classes); + Object.assign(glimmer, data.glimmer); + Object.assign(Views, data.Views); + Object.assign(instrumentation, data.instrumentation); + Object.assign(ENV_, data.ENV); +} + +export const utils = { + libraries, +}; + +export const runloop = { + _backburner, + cancel, + debounce, + join, + later, + scheduleOnce, + run, +}; + +export const object = { + cacheFor, + guidFor, + getOwner, + set, + get, + meta, +}; + +if (!isMandatorySetter) { + isMandatorySetter = function (obj, prop) { + const descriptor = Object.getOwnPropertyDescriptor(obj, prop); + if ( + Ember.MANDATORY_SETTER_FUNCTION && + descriptor?.set === Ember.MANDATORY_SETTER_FUNCTION + ) { + return true; + } + if ( + descriptor?.set && + Function.prototype.toString + .call(descriptor.set) + .includes('You attempted to update') + ) { + return true; + } + return false; + }; } -export { +export const debug = { + isComputed, + isTrackedProperty, + isCachedProperty, + descriptorForProperty, + descriptorForDecorator, + isMandatorySetter, + meta, + captureRenderTree, + isTesting, + inspect, + registerDeprecationHandler, + tagForProperty, + track, + instrumentation: instrumentation_, +}; + +export const classes = { ArrayProxy, - Namespace, + ObjectProxy, ActionHandler, - Application, - ControllerMixin, + ComputedProperty, + EmberObject, MutableArray, + Namespace, MutableEnumerable, NativeArray, + TargetActionSupport, + ControllerMixin, CoreObject, - ObjectProxy, - Component, + Application, + EmberComponent, + GlimmerComponent, Observable, Evented, Service, PromiseProxyMixin, - EmberObject, + RSVP, +}; + +export const Views = { + ViewStateSupport, + ViewMixin, + ActionSupport, + ClassNamesSupport, + ChildViewsSupport, + CoreView, +}; + +export const glimmer = { + validator: GlimmerValidator_, + runtime: GlimmerRuntime_, +}; + +export const instrumentation = instrumentation_; + +export const ENV = ENV_; + +export const ember = { + runloop, + object, + debug, + classes, VERSION, - ComputedProperty, - meta, - computed, - get, - set, - captureRenderTree, - getEnv, + instrumentation: instrumentation_, + Views, + glimmer, + env: ENV_, }; -export default Ember; +export default ember; diff --git a/ember_debug/utils/ember/debug.js b/ember_debug/utils/ember/debug.js deleted file mode 100644 index b20788a823..0000000000 --- a/ember_debug/utils/ember/debug.js +++ /dev/null @@ -1,20 +0,0 @@ -import Ember from '../ember'; - -let module; - -export let inspect; - -try { - module = requireModule('@ember/debug'); - inspect = module.inspect || requireModule('@ember/-internals/utils').inspect; -} catch { - module = Ember.Debug; - inspect = Ember.inspect; -} - -if (!inspect) { - inspect = Ember.inspect; -} - -export let { registerDeprecationHandler } = module; -export default module; diff --git a/ember_debug/utils/ember/instrumentation.js b/ember_debug/utils/ember/instrumentation.js deleted file mode 100644 index 9d4cc070c0..0000000000 --- a/ember_debug/utils/ember/instrumentation.js +++ /dev/null @@ -1,11 +0,0 @@ -import Ember from '../ember'; - -let module; - -try { - module = requireModule('@ember/instrumentation'); -} catch { - module = Ember; -} - -export let { subscribe } = module; diff --git a/ember_debug/utils/ember/object/internals.js b/ember_debug/utils/ember/object/internals.js index fe692c64e5..ce6930dfe5 100644 --- a/ember_debug/utils/ember/object/internals.js +++ b/ember_debug/utils/ember/object/internals.js @@ -5,7 +5,7 @@ let module; try { module = requireModule('@ember/object/internals'); } catch { - module = Ember; + module = Ember.object; } let { cacheFor, guidFor: emberGuidFor } = module; diff --git a/ember_debug/utils/ember/runloop.js b/ember_debug/utils/ember/runloop.js index ea6a900496..538becd9fa 100644 --- a/ember_debug/utils/ember/runloop.js +++ b/ember_debug/utils/ember/runloop.js @@ -1,4 +1,4 @@ -import Ember from '../ember'; +import { runloop as EmberRunloop } from '../ember'; import * as runloop from './own-runloop'; let module = runloop; @@ -6,30 +6,25 @@ let _backburner = runloop._backburner; const keys = ['cancel', 'debounce', 'join', 'later', 'scheduleOnce']; -try { - module = requireModule('@ember/runloop'); - // it could happen that runloop is available but _backburner is not exported (dead code) - // then we need to use our own - _backburner = module._backburner; -} catch { - _backburner = Ember?.run?.backburner || module._backburner; - module = Ember?.run || module; +if (EmberRunloop?._backburner) { + module = EmberRunloop; + _backburner = EmberRunloop._backburner; } if (!keys.every((k) => k in module)) { module = runloop; + _backburner = runloop._backburner; } // if it is our own, run a internal to trigger `end` // required in object inspector & render debug function loop() { - _backburner.later('actions', loop, 300); + _backburner.schedule('actions', loop, 300); } if (_backburner === runloop._backburner) { loop(); } -export let run = runloop.run; export { _backburner }; -export let { cancel, debounce, join, later, scheduleOnce } = module; +export let { cancel, debounce, join, later, scheduleOnce, run } = module; diff --git a/ember_debug/utils/rsvp.js b/ember_debug/utils/rsvp.js deleted file mode 100644 index 840e6516a7..0000000000 --- a/ember_debug/utils/rsvp.js +++ /dev/null @@ -1,20 +0,0 @@ -import Ember from './ember'; - -let module, RSVP; - -try { - module = requireModule('rsvp'); - RSVP = module.default; - - // The RSVP module should have named exports for `Promise`, etc, - // but some old versions do not and provide `RSVP.Promise`, etc. - if (!('Promise' in module)) { - module = RSVP; - } -} catch { - module = RSVP = Ember.RSVP; -} - -export let { Promise, all, resolve } = module; - -export default RSVP; diff --git a/ember_debug/utils/type-check.js b/ember_debug/utils/type-check.js index 9c71aa48bc..7ed0aebff7 100644 --- a/ember_debug/utils/type-check.js +++ b/ember_debug/utils/type-check.js @@ -1,10 +1,4 @@ -import Debug, { inspect as emberInspect } from 'ember-debug/utils/ember/debug'; -import { - ComputedProperty, - EmberObject, - meta as emberMeta, -} from 'ember-debug/utils/ember'; -import { emberSafeRequire } from 'ember-debug/utils/ember/loader'; +import { debug, classes } from 'ember-debug/utils/ember'; /** * Check if given key on the passed object is a computed property @@ -14,15 +8,15 @@ import { emberSafeRequire } from 'ember-debug/utils/ember/loader'; */ export function isComputed(object, key) { // Ember > 3.10 - if (Debug.isComputed && Debug.isComputed(object, key)) { + if (debug.isComputed && debug.isComputed(object, key)) { return true; } - if (emberMeta(object) && emberMeta(object).peekDescriptors(key)) { - return !!emberMeta(object).peekDescriptors(key)._getter; + if (debug.meta(object) && debug.meta(object).peekDescriptors(key)) { + return !!debug.meta(object).peekDescriptors(key)._getter; } - if (getDescriptorFor(object, key) instanceof ComputedProperty) { + if (getDescriptorFor(object, key) instanceof classes.ComputedProperty) { return true; } } @@ -39,12 +33,10 @@ export function getDescriptorFor(object, key) { } // exists longer than ember 3.10 - if (Debug.isComputed) { - const { descriptorForDecorator, descriptorForProperty } = - emberSafeRequire('@ember/-internals/metal') || {}; + if (debug.isComputed) { return ( - descriptorForDecorator?.(object[key]) || - descriptorForProperty?.(object, key) + debug.descriptorForDecorator?.(object[key]) || + debug.descriptorForProperty?.(object, key) ); } @@ -61,7 +53,7 @@ export function typeOf(obj) { export function inspect(value) { if (typeof value === 'function') { return `${value.name || 'function'}() { ... }`; - } else if (value instanceof EmberObject) { + } else if (value instanceof classes.EmberObject) { return value.toString(); } else if (value instanceof HTMLElement) { return `<${value.tagName.toLowerCase()}>`; @@ -128,6 +120,6 @@ export function inspect(value) { } return `{ ${ret.join(', ')}${suffix}`; } else { - return emberInspect(value); + return debug.inspect(value); } } diff --git a/ember_debug/vendor/startup-wrapper.js b/ember_debug/vendor/startup-wrapper.js index 75c6ebbc7f..2a0d9fd57f 100644 --- a/ember_debug/vendor/startup-wrapper.js +++ b/ember_debug/vendor/startup-wrapper.js @@ -1,4 +1,5 @@ let Ember; +let guidFor; /* eslint camelcase:0 */ /** @@ -12,17 +13,17 @@ let Ember; **/ /*eslint prefer-spread: 0 */ /* globals adapter, env */ -var currentAdapter = 'basic'; +let currentAdapter = 'basic'; if (typeof adapter !== 'undefined') { currentAdapter = adapter; } -var currentEnv = 'production'; +let currentEnv = 'production'; if (typeof env !== 'undefined') { currentEnv = env; } // @formatter:off -var EMBER_VERSIONS_SUPPORTED = {{EMBER_VERSIONS_SUPPORTED}}; +let EMBER_VERSIONS_SUPPORTED = {{EMBER_VERSIONS_SUPPORTED}}; // @formatter:on (function(adapter) { @@ -32,12 +33,14 @@ var EMBER_VERSIONS_SUPPORTED = {{EMBER_VERSIONS_SUPPORTED}}; return; } + guidFor = requireModule('ember-debug/utils/ember/object/internals').guidFor; + // If Ember doesn't exist, we should stop here to avoid issues with accessing `Ember.VERSION` - if (!Ember) { + if (!requireModule('ember-debug/utils/ember')?.ember?.VERSION) { return; } - if (!versionTest(Ember.VERSION, EMBER_VERSIONS_SUPPORTED)) { + if (!versionTest(requireModule('ember-debug/utils/ember').ember.VERSION, EMBER_VERSIONS_SUPPORTED)) { // Wrong inspector version. Redirect to the correct version. sendVersionMiss(); return; @@ -105,25 +108,29 @@ var EMBER_VERSIONS_SUPPORTED = {{EMBER_VERSIONS_SUPPORTED}}; function onEmberReady(callback) { var triggered = false; - var triggerOnce = function(string) { + const event = new Event("ember-inspector-debug-request"); + var triggerOnce = function(e) { if (triggered) { return; } - if (!Ember) { - try { - Ember = requireModule('ember')['default']; - } catch { - Ember = window.Ember; - } + if (e && e.detail && typeof e.detail === 'object') { + triggered = true; + requireModule('ember-debug/utils/ember').assignEmberInfo(e.detail); + Ember = requireModule('ember-debug/utils/ember'); + callback(); + return; } + window.dispatchEvent(event); - if (!Ember) { + Ember = requireModule('ember-debug/utils/ember'); + + if (!Ember.ember.VERSION) { return; } // `Ember.Application` load hook triggers before all of Ember is ready. // In this case we ignore and wait for the `Ember` load hook. - if (!Ember.RSVP) { + if (!Ember.classes.RSVP) { return; } triggered = true; @@ -132,8 +139,10 @@ var EMBER_VERSIONS_SUPPORTED = {{EMBER_VERSIONS_SUPPORTED}}; // Newest Ember versions >= 1.10 - const later = () => setTimeout(triggerOnce, 0); + const later = (data) => setTimeout(() => triggerOnce(data), 0); window.addEventListener('Ember', later, { once: true }); + window.addEventListener('ember-inspector-debug-response', later, { once: true }); + window.dispatchEvent(event); // Oldest Ember versions or if this was injected after Ember has loaded. onReady(triggerOnce); } @@ -155,7 +164,7 @@ var EMBER_VERSIONS_SUPPORTED = {{EMBER_VERSIONS_SUPPORTED}}; if (message.type === 'app-selected') { let current = window.EmberInspector._application; - let selected = getApplications().find(app => Ember.guidFor(app) === message.applicationId); + let selected = getApplications().find(app => Ember.object.guidFor(app) === message.applicationId); if (selected && current !== selected && selected.__deprecatedInstance__) { bootEmberInspector(selected.__deprecatedInstance__); @@ -202,9 +211,10 @@ var EMBER_VERSIONS_SUPPORTED = {{EMBER_VERSIONS_SUPPORTED}}; setTimeout(() => loadInstance(app), 0) } }); - } - Ember.Application.initializer({ + + const { Application } = requireModule('ember-debug/utils/ember').classes; + Application.initializer({ name: 'ember-inspector-booted', initialize: function(app) { setupInstanceInitializer(app, callback); @@ -220,7 +230,7 @@ var EMBER_VERSIONS_SUPPORTED = {{EMBER_VERSIONS_SUPPORTED}}; // registering an instance initializer with the same name, even if on a different app, // triggers an error because instance initializers seem to be global instead of per app. app.instanceInitializer({ - name: 'ember-inspector-app-instance-booted-' + Ember.guidFor(app), + name: 'ember-inspector-app-instance-booted-' + guidFor(app), initialize: function(instance) { callback(instance); } @@ -234,16 +244,16 @@ var EMBER_VERSIONS_SUPPORTED = {{EMBER_VERSIONS_SUPPORTED}}; * @return {*} */ function getApplications() { - var namespaces = Ember.A(Ember.Namespace.NAMESPACES); + const namespaces = [...Ember.classes.Namespace.NAMESPACES]; - var apps = namespaces.filter(function(namespace) { - return namespace instanceof Ember.Application; + const apps = namespaces.filter(function (namespace) { + return namespace instanceof Ember.classes.Application; }); return apps.map(function(app) { // Add applicationId and applicationName to the app - var applicationId = Ember.guidFor(app); - var applicationName = app.name || app.modulePrefix || `(unknown app - ${applicationId})`; + const applicationId = guidFor(app); + const applicationName = app.name || app.modulePrefix || `(unknown app - ${applicationId})`; Object.assign(app, { applicationId, @@ -287,7 +297,7 @@ var EMBER_VERSIONS_SUPPORTED = {{EMBER_VERSIONS_SUPPORTED}}; function sendVersionMismatch() { port.postMessage({ name: 'version-mismatch', - version: Ember.VERSION, + version: requireModule('ember-debug/utils/ember').ember.VERSION, from: 'inspectedWindow' }); } diff --git a/skeletons/web-extension/scripts/in-page-script.js b/skeletons/web-extension/scripts/in-page-script.js index d4ad0dd16f..6a127ee522 100644 --- a/skeletons/web-extension/scripts/in-page-script.js +++ b/skeletons/web-extension/scripts/in-page-script.js @@ -24,15 +24,23 @@ window.removeEventListener("load", completed, false); callback(); } + + window.addEventListener('ember-inspector-debug-response', callback, { once: true }); } - onReady(function() { + onReady(function(e) { let Ember; try { Ember = requireModule('ember')['default']; } catch { Ember = window.Ember; } + + if (!Ember) { + const event = new Event("ember-inspector-debug-request"); + document.dispatchEvent(event); + } + var libraries = Ember && Ember.libraries; if (libraries) { // Ember has changed where the array of libraries is located. diff --git a/tests/ember_debug/view-debug-test.js b/tests/ember_debug/view-debug-test.js index 3a58d7c860..408bc97eac 100644 --- a/tests/ember_debug/view-debug-test.js +++ b/tests/ember_debug/view-debug-test.js @@ -18,7 +18,7 @@ import { hbs } from 'ember-cli-htmlbars'; import EmberDebug from 'ember-debug/main'; import setupEmberDebugTest from '../helpers/setup-ember-debug-test'; import { isInVersionSpecifier } from 'ember-debug/utils/version'; -import { VERSION } from 'ember-debug/utils/ember'; +import { ember } from 'ember-debug/utils/ember'; let templateOnlyComponent = null; try { @@ -677,7 +677,10 @@ module('Ember Debug - View', function (hooks) { }) ); } - const enableModifierSupport = isInVersionSpecifier('>3.28.0', VERSION); + const enableModifierSupport = isInVersionSpecifier( + '>3.28.0', + ember.VERSION + ); if (!enableModifierSupport) { modifiers.length = 0; } @@ -733,7 +736,10 @@ module('Ember Debug - View', function (hooks) { let argsTestPromise; - const enableModifierSupport = isInVersionSpecifier('>3.28.0', VERSION); + const enableModifierSupport = isInVersionSpecifier( + '>3.28.0', + ember.VERSION + ); const children = [ Component({ name: 'test-foo', bounds: 'single' }), @@ -859,7 +865,10 @@ module('Ember Debug - View', function (hooks) { ), ]; - const enableModifierSupport = isInVersionSpecifier('>3.28.0', VERSION); + const enableModifierSupport = isInVersionSpecifier( + '>3.28.0', + ember.VERSION + ); if (enableModifierSupport) { root.push(