Skip to content

Commit

Permalink
Merge pull request #1710 from glimmerjs/reproduce-problem-from-ember
Browse files Browse the repository at this point in the history
Fix rendering non-object, yet stringable values (Symbol?), moves Reflect.getPrototypeOf to Object.getPrototypeOf
  • Loading branch information
NullVoxPopuli authored Feb 11, 2025
2 parents da5ebb9 + 0da5b0c commit c918fc9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
21 changes: 21 additions & 0 deletions packages/@glimmer-workspace/integration-tests/test/render-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineComponent, jitSuite, RenderTest, test } from '@glimmer-workspace/integration-tests';

class RenderingTest extends RenderTest {
static suiteName = '<rendering>';

query(selector: string) {
let el = (s: string) => (this.element as unknown as HTMLElement).querySelector(s);
return el(selector) as Element;
}

@test
'Symbols are rendered as strings'() {
const sym = Symbol('hello world');
const Bar = defineComponent({ sym }, '<div>{{sym}}</div>');

this.renderComponent(Bar);
this.assertHTML(`<div>Symbol(hello world)</div>`);
}
}

jitSuite(RenderingTest);
11 changes: 9 additions & 2 deletions packages/@glimmer/manager/lib/internal/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ const HELPER_MANAGERS = new WeakMap<object, CustomHelperManager | Helper>();

///////////

const getPrototypeOf = Reflect.getPrototypeOf;
/**
* There is also Reflect.getPrototypeOf,
* which errors when non-objects are passed.
*
* Since our conditional for figuring out whether to render primitives or not
* may contain non-object values, we don't want to throw errors when we call this.
*/
const getPrototypeOf = Object.getPrototypeOf;

function setManager<Def extends object>(
map: WeakMap<object, object>,
Expand Down Expand Up @@ -65,7 +72,7 @@ function getManager<M extends InternalManager>(
return manager;
}

pointer = getPrototypeOf(pointer);
pointer = getPrototypeOf(pointer) as object | null;
}

return undefined;
Expand Down

0 comments on commit c918fc9

Please sign in to comment.