Skip to content

Commit

Permalink
Merge pull request #1447 from patricklx/patch-3
Browse files Browse the repository at this point in the history
fix: capture render tree can fail if args cannot be obtained
  • Loading branch information
NullVoxPopuli authored Oct 23, 2023
2 parents 47a3e29 + f7d54c1 commit 8caba05
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,29 @@ class DebugRenderTreeTest extends RenderTest {

@test 'emberish curly components'() {
this.registerComponent('Curly', 'HelloWorld', 'Hello World');
let error: Error|null = null;
const obj = {
get getterWithError() {
error = new Error('error');
throw error;
}
}

this.render(
`<HelloWorld @arg="first"/>{{#if this.showSecond}}<HelloWorld @arg="second"/>{{/if}}`,
`<HelloWorld @arg="first" @arg2={{this.obj.getterWithError}}/>{{#if this.showSecond}}<HelloWorld @arg="second"/>{{/if}}`,
{
showSecond: false,
obj,
}
);

this.assert.ok(error !== null, 'expecting an Error');

this.assertRenderTree([
{
type: 'component',
name: 'HelloWorld',
args: { positional: [], named: { arg: 'first' } },
args: { positional: [], named: { arg: 'first', arg2: error } },
instance: (instance: EmberishCurlyComponent) => (instance as any).arg === 'first',
template: '(unknown template module)',
bounds: this.nodeBounds(this.delegate.getInitialElement().firstChild),
Expand All @@ -164,7 +174,7 @@ class DebugRenderTreeTest extends RenderTest {
{
type: 'component',
name: 'HelloWorld',
args: { positional: [], named: { arg: 'first' } },
args: { positional: [], named: { arg: 'first', arg2: error } },
instance: (instance: EmberishCurlyComponent) => (instance as any).arg === 'first',
template: '(unknown template module)',
bounds: this.nodeBounds(this.element.firstChild),
Expand All @@ -187,7 +197,7 @@ class DebugRenderTreeTest extends RenderTest {
{
type: 'component',
name: 'HelloWorld',
args: { positional: [], named: { arg: 'first' } },
args: { positional: [], named: { arg: 'first', arg2: error } },
instance: (instance: EmberishCurlyComponent) => (instance as any).arg === 'first',
template: '(unknown template module)',
bounds: this.nodeBounds(this.element.firstChild),
Expand Down
14 changes: 12 additions & 2 deletions packages/@glimmer/runtime/lib/vm/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,24 @@ export function reifyNamed(named: CapturedNamedArguments) {
let reified = dict();

for (const [key, value] of Object.entries(named)) {
reified[key] = valueForRef(value);
try {
reified[key] = valueForRef(value);
} catch(e) {
reified[key] = e;
}
}

return reified;
}

export function reifyPositional(positional: CapturedPositionalArguments) {
return positional.map(valueForRef);
return positional.map((p) => {
try {
return valueForRef(p);
} catch(e) {
return e;
}
});
}

export function reifyArgs(args: CapturedArguments) {
Expand Down

0 comments on commit 8caba05

Please sign in to comment.