Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@glimmer/program

Package Overview
Dependencies
Maintainers
13
Versions
243
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@glimmer/program - npm Package Compare versions

Comparing version 0.85.5 to 0.85.6

453

dist/prod/index.js

@@ -1,453 +0,2 @@

import { getInternalHelperManager, getInternalModifierManager, getInternalComponentManager, capabilityFlagsFrom, getComponentTemplate, managerHasCapability } from '@glimmer/manager';
import { templateFactory } from '@glimmer/opcode-compiler';
import { constants, enumerate, assert, unwrapTemplate, expect, unwrap } from '@glimmer/util';
import { InternalComponentCapabilities, OPERAND_LEN_MASK, ARG_SHIFT, MACHINE_MASK, TYPE_MASK } from '@glimmer/vm';
import { SexpOpcodes } from '@glimmer/wire-format';
/**
* Default component template, which is a plain yield
*/
const DEFAULT_TEMPLATE_BLOCK = [[[SexpOpcodes.Yield, 1, null]], ['&default'], false, []];
const DEFAULT_TEMPLATE = {
// random uuid
id: '1b32f5c2-7623-43d6-a0ad-9672898920a1',
moduleName: '__default__.hbs',
block: JSON.stringify(DEFAULT_TEMPLATE_BLOCK),
scope: null,
isStrictMode: true
};
const WELL_KNOWN_EMPTY_ARRAY = Object.freeze([]);
const STARTER_CONSTANTS = constants(WELL_KNOWN_EMPTY_ARRAY);
const WELL_KNOWN_EMPTY_ARRAY_POSITION = STARTER_CONSTANTS.indexOf(WELL_KNOWN_EMPTY_ARRAY);
class CompileTimeConstantImpl {
// `0` means NULL
values = STARTER_CONSTANTS.slice();
indexMap = new Map(this.values.map((value, index) => [value, index]));
value(value) {
let indexMap = this.indexMap;
let index = indexMap.get(value);
if (index === undefined) {
index = this.values.push(value) - 1;
indexMap.set(value, index);
}
return index;
}
array(values) {
if (values.length === 0) {
return WELL_KNOWN_EMPTY_ARRAY_POSITION;
}
let handles = new Array(values.length);
for (let i = 0; i < values.length; i++) {
handles[i] = this.value(values[i]);
}
return this.value(handles);
}
toPool() {
return this.values;
}
}
class RuntimeConstantsImpl {
values;
constructor(pool) {
this.values = pool;
}
getValue(handle) {
return this.values[handle];
}
getArray(value) {
let handles = this.getValue(value);
let reified = new Array(handles.length);
for (const [i, n] of enumerate(handles)) {
reified[i] = this.getValue(n);
}
return reified;
}
}
class ConstantsImpl extends CompileTimeConstantImpl {
reifiedArrs = {
[WELL_KNOWN_EMPTY_ARRAY_POSITION]: WELL_KNOWN_EMPTY_ARRAY
};
defaultTemplate = templateFactory(DEFAULT_TEMPLATE)();
// Used for tests and debugging purposes, and to be able to analyze large apps
// This is why it's enabled even in production
helperDefinitionCount = 0;
modifierDefinitionCount = 0;
componentDefinitionCount = 0;
helperDefinitionCache = new WeakMap();
modifierDefinitionCache = new WeakMap();
componentDefinitionCache = new WeakMap();
helper(definitionState) {
let isOptional = arguments.length > 2 ? arguments[2] : undefined;
let handle = this.helperDefinitionCache.get(definitionState);
if (handle === undefined) {
let managerOrHelper = getInternalHelperManager(definitionState, isOptional);
if (managerOrHelper === null) {
this.helperDefinitionCache.set(definitionState, null);
return null;
}
assert(managerOrHelper, 'BUG: expected manager or helper');
let helper = typeof managerOrHelper === 'function' ? managerOrHelper : managerOrHelper.getHelper(definitionState);
handle = this.value(helper);
this.helperDefinitionCache.set(definitionState, handle);
this.helperDefinitionCount++;
}
return handle;
}
modifier(definitionState) {
let resolvedName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
let isOptional = arguments.length > 2 ? arguments[2] : undefined;
let handle = this.modifierDefinitionCache.get(definitionState);
if (handle === undefined) {
let manager = getInternalModifierManager(definitionState, isOptional);
if (manager === null) {
this.modifierDefinitionCache.set(definitionState, null);
return null;
}
let definition = {
resolvedName,
manager,
state: definitionState
};
handle = this.value(definition);
this.modifierDefinitionCache.set(definitionState, handle);
this.modifierDefinitionCount++;
}
return handle;
}
component(definitionState, owner, isOptional) {
let definition = this.componentDefinitionCache.get(definitionState);
if (definition === undefined) {
let manager = getInternalComponentManager(definitionState, isOptional);
if (manager === null) {
this.componentDefinitionCache.set(definitionState, null);
return null;
}
assert(manager, 'BUG: expected manager');
let capabilities = capabilityFlagsFrom(manager.getCapabilities(definitionState));
let templateFactory = getComponentTemplate(definitionState);
let compilable = null;
let template;
if (!managerHasCapability(manager, capabilities, InternalComponentCapabilities.dynamicLayout)) {
template = templateFactory?.(owner) ?? this.defaultTemplate;
} else {
template = templateFactory?.(owner);
}
if (template !== undefined) {
template = unwrapTemplate(template);
compilable = managerHasCapability(manager, capabilities, InternalComponentCapabilities.wrapped) ? template.asWrappedLayout() : template.asLayout();
}
definition = {
resolvedName: null,
handle: -1,
// replaced momentarily
manager,
capabilities,
state: definitionState,
compilable
};
definition.handle = this.value(definition);
this.componentDefinitionCache.set(definitionState, definition);
this.componentDefinitionCount++;
}
return definition;
}
resolvedComponent(resolvedDefinition, resolvedName) {
let definition = this.componentDefinitionCache.get(resolvedDefinition);
if (definition === undefined) {
let {
manager,
state,
template
} = resolvedDefinition;
let capabilities = capabilityFlagsFrom(manager.getCapabilities(resolvedDefinition));
let compilable = null;
if (!managerHasCapability(manager, capabilities, InternalComponentCapabilities.dynamicLayout)) {
template = template ?? this.defaultTemplate;
}
if (template !== null) {
template = unwrapTemplate(template);
compilable = managerHasCapability(manager, capabilities, InternalComponentCapabilities.wrapped) ? template.asWrappedLayout() : template.asLayout();
}
definition = {
resolvedName,
handle: -1,
// replaced momentarily
manager,
capabilities,
state,
compilable
};
definition.handle = this.value(definition);
this.componentDefinitionCache.set(resolvedDefinition, definition);
this.componentDefinitionCount++;
}
return expect(definition, 'BUG: resolved component definitions cannot be null');
}
getValue(index) {
assert(index >= 0, `cannot get value for handle: ${index}`);
return this.values[index];
}
getArray(index) {
let reifiedArrs = this.reifiedArrs;
let reified = reifiedArrs[index];
if (reified === undefined) {
let names = this.getValue(index);
reified = new Array(names.length);
for (const [i, name] of enumerate(names)) {
reified[i] = this.getValue(name);
}
reifiedArrs[index] = reified;
}
return reified;
}
}
const LOCAL_DEBUG = (() => {
let location = typeof window !== 'undefined' && window.location;
if (location && /[&?]disable_local_debug/u.test(window.location.search)) {
return false;
}
return true;
})();
class RuntimeOpImpl {
offset = 0;
constructor(heap) {
this.heap = heap;
}
get size() {
let rawType = this.heap.getbyaddr(this.offset);
return ((rawType & OPERAND_LEN_MASK) >> ARG_SHIFT) + 1;
}
get isMachine() {
let rawType = this.heap.getbyaddr(this.offset);
return rawType & MACHINE_MASK ? 1 : 0;
}
get type() {
return this.heap.getbyaddr(this.offset) & TYPE_MASK;
}
get op1() {
return this.heap.getbyaddr(this.offset + 1);
}
get op2() {
return this.heap.getbyaddr(this.offset + 2);
}
get op3() {
return this.heap.getbyaddr(this.offset + 3);
}
}
var TableSlotState = /*#__PURE__*/function (TableSlotState) {
TableSlotState[TableSlotState["Allocated"] = 0] = "Allocated";
TableSlotState[TableSlotState["Freed"] = 1] = "Freed";
TableSlotState[TableSlotState["Purged"] = 2] = "Purged";
TableSlotState[TableSlotState["Pointer"] = 3] = "Pointer";
return TableSlotState;
}(TableSlotState || {});
const PAGE_SIZE = 0x100000;
class RuntimeHeapImpl {
heap;
table;
constructor(serializedHeap) {
let {
buffer,
table
} = serializedHeap;
this.heap = new Int32Array(buffer);
this.table = table;
}
// It is illegal to close over this address, as compaction
// may move it. However, it is legal to use this address
// multiple times between compactions.
getaddr(handle) {
return unwrap(this.table[handle]);
}
getbyaddr(address) {
return expect(this.heap[address], 'Access memory out of bounds of the heap');
}
sizeof(handle) {
return sizeof(this.table, handle);
}
}
function hydrateHeap(serializedHeap) {
return new RuntimeHeapImpl(serializedHeap);
}
/**
* The Heap is responsible for dynamically allocating
* memory in which we read/write the VM's instructions
* from/to. When we malloc we pass out a VMHandle, which
* is used as an indirect way of accessing the memory during
* execution of the VM. Internally we track the different
* regions of the memory in an int array known as the table.
*
* The table 32-bit aligned and has the following layout:
*
* | ... | hp (u32) | info (u32) | size (u32) |
* | ... | Handle | Scope Size | State | Size |
* | ... | 32bits | 30bits | 2bits | 32bit |
*
* With this information we effectively have the ability to
* control when we want to free memory. That being said you
* can not free during execution as raw address are only
* valid during the execution. This means you cannot close
* over them as you will have a bad memory access exception.
*/
class HeapImpl {
offset = 0;
heap;
handleTable;
handleState;
handle = 0;
constructor() {
this.heap = new Int32Array(PAGE_SIZE);
this.handleTable = [];
this.handleState = [];
}
pushRaw(value) {
this.sizeCheck();
this.heap[this.offset++] = value;
}
pushOp(item) {
this.pushRaw(item);
}
pushMachine(item) {
this.pushRaw(item | MACHINE_MASK);
}
sizeCheck() {
let {
heap
} = this;
if (this.offset === this.heap.length) {
let newHeap = new Int32Array(heap.length + PAGE_SIZE);
newHeap.set(heap, 0);
this.heap = newHeap;
}
}
getbyaddr(address) {
return unwrap(this.heap[address]);
}
setbyaddr(address, value) {
this.heap[address] = value;
}
malloc() {
// push offset, info, size
this.handleTable.push(this.offset);
return this.handleTable.length - 1;
}
finishMalloc(handle) {
// @TODO: At the moment, garbage collection isn't actually used, so this is
// wrapped to prevent us from allocating extra space in prod. In the future,
// if we start using the compact API, we should change this.
if (LOCAL_DEBUG) {
this.handleState[handle] = TableSlotState.Allocated;
}
}
size() {
return this.offset;
}
// It is illegal to close over this address, as compaction
// may move it. However, it is legal to use this address
// multiple times between compactions.
getaddr(handle) {
return unwrap(this.handleTable[handle]);
}
sizeof(handle) {
return sizeof(this.handleTable, handle);
}
free(handle) {
this.handleState[handle] = TableSlotState.Freed;
}
/**
* The heap uses the [Mark-Compact Algorithm](https://en.wikipedia.org/wiki/Mark-compact_algorithm) to shift
* reachable memory to the bottom of the heap and freeable
* memory to the top of the heap. When we have shifted all
* the reachable memory to the top of the heap, we move the
* offset to the next free position.
*/
compact() {
let compactedSize = 0;
let {
handleTable,
handleState,
heap
} = this;
for (let i = 0; i < length; i++) {
let offset = unwrap(handleTable[i]);
let size = unwrap(handleTable[i + 1]) - unwrap(offset);
let state = handleState[i];
if (state === TableSlotState.Purged) {
continue;
} else if (state === TableSlotState.Freed) {
// transition to "already freed" aka "purged"
// a good improvement would be to reuse
// these slots
handleState[i] = TableSlotState.Purged;
compactedSize += size;
} else if (state === TableSlotState.Allocated) {
for (let j = offset; j <= i + size; j++) {
heap[j - compactedSize] = unwrap(heap[j]);
}
handleTable[i] = offset - compactedSize;
} else if (state === TableSlotState.Pointer) {
handleTable[i] = offset - compactedSize;
}
}
this.offset = this.offset - compactedSize;
}
capture() {
let offset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.offset;
// Only called in eager mode
let buffer = slice(this.heap, 0, offset).buffer;
return {
handle: this.handle,
table: this.handleTable,
buffer: buffer
};
}
}
class RuntimeProgramImpl {
_opcode;
constructor(constants, heap) {
this.constants = constants;
this.heap = heap;
this._opcode = new RuntimeOpImpl(this.heap);
}
opcode(offset) {
this._opcode.offset = offset;
return this._opcode;
}
}
function slice(arr, start, end) {
if (arr.slice !== undefined) {
return arr.slice(start, end);
}
let ret = new Int32Array(end);
for (; start < end; start++) {
ret[start] = unwrap(arr[start]);
}
return ret;
}
function sizeof(table, handle) {
if (LOCAL_DEBUG) {
return unwrap(table[handle + 1]) - unwrap(table[handle]);
} else {
return -1;
}
}
function artifacts() {
return {
constants: new ConstantsImpl(),
heap: new HeapImpl()
};
}
export { CompileTimeConstantImpl, ConstantsImpl, HeapImpl, RuntimeConstantsImpl, RuntimeHeapImpl, RuntimeOpImpl, RuntimeProgramImpl, artifacts, hydrateHeap };
import{getInternalHelperManager as e,getInternalModifierManager as t,getInternalComponentManager as i,capabilityFlagsFrom as n,getComponentTemplate as a,managerHasCapability as r}from"@glimmer/manager";import{templateFactory as l}from"@glimmer/opcode-compiler";import{constants as s,enumerate as o,assert as h,unwrapTemplate as u,expect as f,unwrap as d}from"@glimmer/util";import{InternalComponentCapabilities as p,OPERAND_LEN_MASK as c,ARG_SHIFT as m,MACHINE_MASK as g,TYPE_MASK as b}from"@glimmer/vm";import{SexpOpcodes as v}from"@glimmer/wire-format";const y=[[[v.Yield,1,null]],["&default"],!1,[]],w={id:"1b32f5c2-7623-43d6-a0ad-9672898920a1",moduleName:"__default__.hbs",block:JSON.stringify(y),scope:null,isStrictMode:!0},C=Object.freeze([]),D=s(C),A=D.indexOf(C);class T{values=D.slice();indexMap=new Map(this.values.map(((e,t)=>[e,t])));value(e){let t=this.indexMap,i=t.get(e);return void 0===i&&(i=this.values.push(e)-1,t.set(e,i)),i}array(e){if(0===e.length)return A;let t=new Array(e.length);for(let i=0;i<e.length;i++)t[i]=this.value(e[i]);return this.value(t)}toPool(){return this.values}}class M{values;constructor(e){this.values=e}getValue(e){return this.values[e]}getArray(e){let t=this.getValue(e),i=new Array(t.length);for(const[e,n]of o(t))i[e]=this.getValue(n);return i}}class _ extends T{reifiedArrs={[A]:C};defaultTemplate=l(w)();helperDefinitionCount=0;modifierDefinitionCount=0;componentDefinitionCount=0;helperDefinitionCache=new WeakMap;modifierDefinitionCache=new WeakMap;componentDefinitionCache=new WeakMap;helper(t){let i=arguments.length>2?arguments[2]:void 0,n=this.helperDefinitionCache.get(t);if(void 0===n){let a=e(t,i);if(null===a)return this.helperDefinitionCache.set(t,null),null;h(a,"BUG: expected manager or helper");let r="function"==typeof a?a:a.getHelper(t);n=this.value(r),this.helperDefinitionCache.set(t,n),this.helperDefinitionCount++}return n}modifier(e){let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2?arguments[2]:void 0,a=this.modifierDefinitionCache.get(e);if(void 0===a){let r=t(e,n);if(null===r)return this.modifierDefinitionCache.set(e,null),null;let l={resolvedName:i,manager:r,state:e};a=this.value(l),this.modifierDefinitionCache.set(e,a),this.modifierDefinitionCount++}return a}component(e,t,l){let s=this.componentDefinitionCache.get(e);if(void 0===s){let o=i(e,l);if(null===o)return this.componentDefinitionCache.set(e,null),null;h(o,"BUG: expected manager");let f,d=n(o.getCapabilities(e)),c=a(e),m=null;f=r(o,d,p.dynamicLayout)?c?.(t):c?.(t)??this.defaultTemplate,void 0!==f&&(f=u(f),m=r(o,d,p.wrapped)?f.asWrappedLayout():f.asLayout()),s={resolvedName:null,handle:-1,manager:o,capabilities:d,state:e,compilable:m},s.handle=this.value(s),this.componentDefinitionCache.set(e,s),this.componentDefinitionCount++}return s}resolvedComponent(e,t){let i=this.componentDefinitionCache.get(e);if(void 0===i){let{manager:a,state:l,template:s}=e,o=n(a.getCapabilities(e)),h=null;r(a,o,p.dynamicLayout)||(s=s??this.defaultTemplate),null!==s&&(s=u(s),h=r(a,o,p.wrapped)?s.asWrappedLayout():s.asLayout()),i={resolvedName:t,handle:-1,manager:a,capabilities:o,state:l,compilable:h},i.handle=this.value(i),this.componentDefinitionCache.set(e,i),this.componentDefinitionCount++}return f(i,"BUG: resolved component definitions cannot be null")}getValue(e){return h(e>=0,`cannot get value for handle: ${e}`),this.values[e]}getArray(e){let t=this.reifiedArrs,i=t[e];if(void 0===i){let n=this.getValue(e);i=new Array(n.length);for(const[e,t]of o(n))i[e]=this.getValue(t);t[e]=i}return i}}const P=!("undefined"!=typeof window&&window.location&&/[&?]disable_local_debug/u.test(window.location.search));class x{offset=0;constructor(e){this.heap=e}get size(){return 1+((this.heap.getbyaddr(this.offset)&c)>>m)}get isMachine(){return this.heap.getbyaddr(this.offset)&g?1:0}get type(){return this.heap.getbyaddr(this.offset)&b}get op1(){return this.heap.getbyaddr(this.offset+1)}get op2(){return this.heap.getbyaddr(this.offset+2)}get op3(){return this.heap.getbyaddr(this.offset+3)}}var z=function(e){return e[e.Allocated=0]="Allocated",e[e.Freed=1]="Freed",e[e.Purged=2]="Purged",e[e.Pointer=3]="Pointer",e}(z||{});const S=1048576;class k{heap;table;constructor(e){let{buffer:t,table:i}=e;this.heap=new Int32Array(t),this.table=i}getaddr(e){return d(this.table[e])}getbyaddr(e){return f(this.heap[e],"Access memory out of bounds of the heap")}sizeof(e){return W(this.table,e)}}function L(e){return new k(e)}class V{offset=0;heap;handleTable;handleState;handle=0;constructor(){this.heap=new Int32Array(S),this.handleTable=[],this.handleState=[]}pushRaw(e){this.sizeCheck(),this.heap[this.offset++]=e}pushOp(e){this.pushRaw(e)}pushMachine(e){this.pushRaw(e|g)}sizeCheck(){let{heap:e}=this;if(this.offset===this.heap.length){let t=new Int32Array(e.length+S);t.set(e,0),this.heap=t}}getbyaddr(e){return d(this.heap[e])}setbyaddr(e,t){this.heap[e]=t}malloc(){return this.handleTable.push(this.offset),this.handleTable.length-1}finishMalloc(e){P&&(this.handleState[e]=z.Allocated)}size(){return this.offset}getaddr(e){return d(this.handleTable[e])}sizeof(e){return W(this.handleTable,e)}free(e){this.handleState[e]=z.Freed}compact(){let e=0,{handleTable:t,handleState:i,heap:n}=this;for(let a=0;a<length;a++){let r=d(t[a]),l=d(t[a+1])-d(r),s=i[a];if(s!==z.Purged)if(s===z.Freed)i[a]=z.Purged,e+=l;else if(s===z.Allocated){for(let t=r;t<=a+l;t++)n[t-e]=d(n[t]);t[a]=r-e}else s===z.Pointer&&(t[a]=r-e)}this.offset=this.offset-e}capture(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.offset,t=function(e,t,i){if(void 0!==e.slice)return e.slice(t,i);let n=new Int32Array(i);for(;t<i;t++)n[t]=d(e[t]);return n}(this.heap,0,e).buffer;return{handle:this.handle,table:this.handleTable,buffer:t}}}class N{_opcode;constructor(e,t){this.constants=e,this.heap=t,this._opcode=new x(this.heap)}opcode(e){return this._opcode.offset=e,this._opcode}}function W(e,t){return P?d(e[t+1])-d(e[t]):-1}function F(){return{constants:new _,heap:new V}}export{T as CompileTimeConstantImpl,_ as ConstantsImpl,V as HeapImpl,M as RuntimeConstantsImpl,k as RuntimeHeapImpl,x as RuntimeOpImpl,N as RuntimeProgramImpl,F as artifacts,L as hydrateHeap};
//# sourceMappingURL=index.js.map

18

package.json
{
"name": "@glimmer/program",
"type": "module",
"version": "0.85.5",
"version": "0.85.6",
"repository": "https://github.com/glimmerjs/glimmer-vm/tree/master/packages/@glimmer/program",

@@ -11,9 +11,9 @@ "files": [

"@glimmer/env": "0.1.7",
"@glimmer/util": "^0.85.5",
"@glimmer/opcode-compiler": "^0.85.5",
"@glimmer/manager": "^0.85.5",
"@glimmer/interfaces": "^0.85.5",
"@glimmer/encoder": "^0.85.5",
"@glimmer/wire-format": "^0.85.5",
"@glimmer/vm": "^0.85.5"
"@glimmer/util": "^0.85.6",
"@glimmer/opcode-compiler": "^0.85.6",
"@glimmer/manager": "^0.85.6",
"@glimmer/interfaces": "^0.85.6",
"@glimmer/encoder": "^0.85.6",
"@glimmer/wire-format": "^0.85.6",
"@glimmer/vm": "^0.85.6"
},

@@ -24,3 +24,3 @@ "devDependencies": {

"publint": "^0.2.5",
"@glimmer/local-debug-flags": "^0.85.5",
"@glimmer/local-debug-flags": "^0.85.6",
"@glimmer-workspace/build-support": "^1.0.0"

@@ -27,0 +27,0 @@ },

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc