Skip to content

Commit c918fc9

Browse files
Merge pull request #1710 from glimmerjs/reproduce-problem-from-ember
Fix rendering non-object, yet stringable values (Symbol?), moves Reflect.getPrototypeOf to Object.getPrototypeOf
2 parents da5ebb9 + 0da5b0c commit c918fc9

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { defineComponent, jitSuite, RenderTest, test } from '@glimmer-workspace/integration-tests';
2+
3+
class RenderingTest extends RenderTest {
4+
static suiteName = '<rendering>';
5+
6+
query(selector: string) {
7+
let el = (s: string) => (this.element as unknown as HTMLElement).querySelector(s);
8+
return el(selector) as Element;
9+
}
10+
11+
@test
12+
'Symbols are rendered as strings'() {
13+
const sym = Symbol('hello world');
14+
const Bar = defineComponent({ sym }, '<div>{{sym}}</div>');
15+
16+
this.renderComponent(Bar);
17+
this.assertHTML(`<div>Symbol(hello world)</div>`);
18+
}
19+
}
20+
21+
jitSuite(RenderingTest);

packages/@glimmer/manager/lib/internal/api.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ const HELPER_MANAGERS = new WeakMap<object, CustomHelperManager | Helper>();
2424

2525
///////////
2626

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

2936
function setManager<Def extends object>(
3037
map: WeakMap<object, object>,
@@ -65,7 +72,7 @@ function getManager<M extends InternalManager>(
6572
return manager;
6673
}
6774

68-
pointer = getPrototypeOf(pointer);
75+
pointer = getPrototypeOf(pointer) as object | null;
6976
}
7077

7178
return undefined;

0 commit comments

Comments
 (0)