Skip to content

cannot coerce undefined to object! in template literal #259

@dckc

Description

@dckc

The template literal expression here throws; is that by design? I'm looking thru various specs and docs and stuff and I can't quite tell whether this OK. The diagnostic is misleading, since neither Object(undefined) nor String(undefined) throws.

export default function main() {
  const undef = undefined;
  const o = Object(undefined);
  const s0 = String(undefined);
  const s = `undef:${undef}`;
  trace(s + '\n');
}

If I try to make my own template tag, the 2nd arg seems to get undefined rather than an array of values. The exception comes on the parts.push line, presumably when evaluating args[i - 1]:

export default function main() {
  const undef = undefined;
  const o = Object(undefined);
  const s0 = String(undefined);
  const s = allstr`undef:${undef}`;
  trace(s + '\n');
}


function allstr(quasis, args) {
  const parts = [quasis[0]];
  for (let i = 1; i < quasis.length; i += 1) {
    parts.push(String(args[i - 1]), quasis[i]);
  }
  return parts.join('');
}

context:
https://github.com/Agoric/SwingSet/blob/a74f608035bbb33f7cc6846c69fd16993131bc48/src/kernel/liveSlots.js#L150

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions