Skip to content

Commit a6d1fbf

Browse files
committed
Fix accessing private members on extension classes.
Since the member was already a symbol, canonicalMember() was incorrectly double wrapping it. Fixes #508. [email protected] Review URL: https://codereview.chromium.org/1944293003 .
1 parent 56b9d09 commit a6d1fbf

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

pkg/dev_compiler/lib/runtime/dart_sdk.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ dart_library.library('dart_sdk', null, /* Imports */[
239239
});
240240
};
241241
dart.canonicalMember = function(obj, name) {
242+
if (typeof name === 'symbol') return name;
242243
if (obj != null && obj[dart._extensionType]) return dart.dartx[name];
243244
if (name == 'constructor' || name == 'prototype') {
244245
name = '+' + name;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:expect/expect.dart';
6+
7+
import 'dart:html';
8+
9+
main() {
10+
// Regression test for: https://github.com/dart-lang/dev_compiler/issues/508.
11+
// "dart:html" defines some private members on native DOM types and we need
12+
// to ensure those can be accessed correctly.
13+
//
14+
// The createFragment() method sets `_innerHtml` on the element, so we use it
15+
// as a test case.
16+
Expect.equals("[object DocumentFragment]",
17+
new BRElement().createFragment("Hi").toString());
18+
}

pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ defineExtensionMembers(type, methodNames) => JS('', '''(() => {
343343
})()''');
344344

345345
canonicalMember(obj, name) => JS('', '''(() => {
346+
// Private names are symbols and are already canonical.
347+
if (typeof name === 'symbol') return name;
348+
346349
if ($obj != null && $obj[$_extensionType]) return $dartx[$name];
347350
// Check for certain names that we can't use in JS
348351
if ($name == 'constructor' || $name == 'prototype') {

0 commit comments

Comments
 (0)