From a6d1fbfb9da0c91be96584a3e89b081a5de00ba9 Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Wed, 4 May 2016 15:04:00 -0700 Subject: [PATCH] Fix accessing private members on extension classes. Since the member was already a symbol, canonicalMember() was incorrectly double wrapping it. Fixes #508. R=vsm@google.com Review URL: https://codereview.chromium.org/1944293003 . --- pkg/dev_compiler/lib/runtime/dart_sdk.js | 1 + .../html/private_extension_member_test.dart | 18 ++++++++++++++++++ .../input_sdk/private/ddc_runtime/classes.dart | 3 +++ 3 files changed, 22 insertions(+) create mode 100644 pkg/dev_compiler/test/codegen/lib/html/private_extension_member_test.dart diff --git a/pkg/dev_compiler/lib/runtime/dart_sdk.js b/pkg/dev_compiler/lib/runtime/dart_sdk.js index 9357634fd901..5b35aa4db4d5 100644 --- a/pkg/dev_compiler/lib/runtime/dart_sdk.js +++ b/pkg/dev_compiler/lib/runtime/dart_sdk.js @@ -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; diff --git a/pkg/dev_compiler/test/codegen/lib/html/private_extension_member_test.dart b/pkg/dev_compiler/test/codegen/lib/html/private_extension_member_test.dart new file mode 100644 index 000000000000..4512d9edf33a --- /dev/null +++ b/pkg/dev_compiler/test/codegen/lib/html/private_extension_member_test.dart @@ -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()); +} diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart index 56920e109f8d..86923f83c33d 100644 --- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart +++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart @@ -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') {