mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 20:51:19 +00:00
912005267d
Change-Id: I46be49b2effec3e38a3dc44cd45cfe736f77fa78 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182680 Commit-Queue: Sigmund Cherem <sigmund@google.com> Reviewed-by: Joshua Litt <joshualitt@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com> Reviewed-by: Stephen Adams <sra@google.com>
110 lines
2.7 KiB
Dart
110 lines
2.7 KiB
Dart
// Copyright (c) 2011, 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.
|
|
|
|
// @dart = 2.7
|
|
|
|
import "native_testing.dart";
|
|
|
|
// Verify that we can have fields with names that start with g and s even
|
|
// though those names are reserved for getters and setters in minified mode.
|
|
|
|
// Note: this works because end and send are both in the list of
|
|
// reservedNativeProperties. In general we don't check arbitrary
|
|
// names for clashes because it's hard - subclasses can force superclasses
|
|
// to rename getters, and that can force unrelated classes to change their
|
|
// getters too if they have a property that has the same name.
|
|
@Native("A")
|
|
class A {
|
|
int bar;
|
|
int g;
|
|
int s;
|
|
int end;
|
|
int gend;
|
|
int send;
|
|
int gettersCalled;
|
|
int settersCalled;
|
|
}
|
|
|
|
void setup() {
|
|
JS('', r"""
|
|
(function(){
|
|
function getter() {
|
|
this.gettersCalled++;
|
|
return 42;
|
|
}
|
|
|
|
function setter(x) {
|
|
this.settersCalled++;
|
|
return 314;
|
|
}
|
|
|
|
var descriptor = {
|
|
get: getter,
|
|
set: setter,
|
|
configurable: false,
|
|
writeable: false
|
|
};
|
|
|
|
function A(){
|
|
var a = Object.create(
|
|
{ constructor: A },
|
|
{ bar: descriptor,
|
|
g: descriptor,
|
|
s: descriptor,
|
|
end: descriptor,
|
|
gend: descriptor,
|
|
send: descriptor
|
|
});
|
|
a.gettersCalled = 0;
|
|
a.settersCalled = 0;
|
|
return a;
|
|
}
|
|
|
|
self.makeA = function() { return new A(); };
|
|
self.nativeConstructor(A);
|
|
})()""");
|
|
applyTestExtensions(['A']);
|
|
}
|
|
|
|
A makeA() native;
|
|
|
|
class B {}
|
|
|
|
main() {
|
|
nativeTesting();
|
|
setup();
|
|
confuse(new B());
|
|
var a = makeA();
|
|
|
|
Expect.equals(42, confuse(a).bar);
|
|
Expect.equals(42, confuse(a).g);
|
|
Expect.equals(42, confuse(a).s);
|
|
Expect.equals(42, confuse(a).end);
|
|
Expect.equals(42, confuse(a).gend);
|
|
Expect.equals(42, confuse(a).send);
|
|
Expect.equals(271, confuse(a).bar = 271);
|
|
Expect.equals(271, confuse(a).g = 271);
|
|
Expect.equals(271, confuse(a).s = 271);
|
|
Expect.equals(271, confuse(a).end = 271);
|
|
Expect.equals(271, confuse(a).gend = 271);
|
|
Expect.equals(271, confuse(a).send = 271);
|
|
Expect.equals(6, confuse(a).gettersCalled);
|
|
Expect.equals(6, confuse(a).settersCalled);
|
|
|
|
Expect.equals(42, a.bar);
|
|
Expect.equals(42, a.g);
|
|
Expect.equals(42, a.s);
|
|
Expect.equals(42, a.end);
|
|
Expect.equals(42, a.gend);
|
|
Expect.equals(42, a.send);
|
|
Expect.equals(271, a.bar = 271);
|
|
Expect.equals(271, a.g = 271);
|
|
Expect.equals(271, a.s = 271);
|
|
Expect.equals(271, a.end = 271);
|
|
Expect.equals(271, a.gend = 271);
|
|
Expect.equals(271, a.send = 271);
|
|
Expect.equals(12, a.gettersCalled);
|
|
Expect.equals(12, a.settersCalled);
|
|
}
|