Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering non-object, yet stringable values (Symbol?), moves Reflect.getPrototypeOf to Object.getPrototypeOf #1710

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading