Skip to content

Commit

Permalink
Fix accessing private members on extension classes.
Browse files Browse the repository at this point in the history
Since the member was already a symbol, canonicalMember() was incorrectly
double wrapping it.

Fixes #508.

[email protected]

Review URL: https://codereview.chromium.org/1944293003 .
  • Loading branch information
munificent committed May 4, 2016
1 parent 56b9d09 commit a6d1fbf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/dev_compiler/lib/runtime/dart_sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ dart_library.library('dart_sdk', null, /* Imports */[
});
};
dart.canonicalMember = function(obj, name) {
if (typeof name === 'symbol') return name;
if (obj != null && obj[dart._extensionType]) return dart.dartx[name];
if (name == 'constructor' || name == 'prototype') {
name = '+' + name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:expect/expect.dart';

import 'dart:html';

main() {
// Regression test for: https://github.com/dart-lang/dev_compiler/issues/508.
// "dart:html" defines some private members on native DOM types and we need
// to ensure those can be accessed correctly.
//
// The createFragment() method sets `_innerHtml` on the element, so we use it
// as a test case.
Expect.equals("[object DocumentFragment]",
new BRElement().createFragment("Hi").toString());
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ defineExtensionMembers(type, methodNames) => JS('', '''(() => {
})()''');

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

0 comments on commit a6d1fbf

Please sign in to comment.