Skip to content

Commit

Permalink
Bug 1642476 - Correctly name anonymous private functions bound to pri…
Browse files Browse the repository at this point in the history
…vate fields. r=jorendorff

Differential Revision: https://phabricator.services.mozilla.com/D77930
  • Loading branch information
mgaudet committed Jul 7, 2020
1 parent c3ea63c commit 6d59d2f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
31 changes: 31 additions & 0 deletions js/src/tests/non262/PrivateName/names.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// |reftest| skip-if(!xulRuntime.shell) shell-option(--enable-private-fields)

var C = class {
static #field = () => 'Test262';
static field = () => 'Test262';
#instance = () => 'Test262';
instance = () => 'Test262';

static accessPrivateField() {
return this.#field;
}

accessPrivateInstanceField() {
return this.#instance;
}

static accessField() {
return this.field;
}

accessInstanceField() {
return this.instance;
}
}
assertEq(C.accessPrivateField().name, '#field')
assertEq(C.accessField().name, 'field');
var c = new C;
assertEq(c.accessPrivateInstanceField().name, '#instance');
assertEq(c.accessInstanceField().name, 'instance');

if (typeof reportCompare === 'function') reportCompare(0, 0);
16 changes: 13 additions & 3 deletions js/src/vm/JSFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2362,9 +2362,19 @@ static JSAtom* SymbolToFunctionName(JSContext* cx, JS::Symbol* symbol,

// Step 4.b.
if (desc) {
// Step 4.c.
if (!sb.append('[') || !sb.append(desc) || !sb.append(']')) {
return nullptr;
// Note: Private symbols are wedged in, as implementation wise they're
// PrivateNameSymbols with a the source level name as a description
// i.e. obj.#f desugars to obj.[PrivateNameSymbol("#f")], however
// they don't use the symbol naming, but rather property naming.
if (symbol->isPrivateName()) {
if (!sb.append(desc)) {
return nullptr;
}
} else {
// Step 4.c.
if (!sb.append('[') || !sb.append(desc) || !sb.append(']')) {
return nullptr;
}
}
}
return sb.finishAtom();
Expand Down

0 comments on commit 6d59d2f

Please sign in to comment.