dart-sdk/tests/corelib/dynamic_nosuchmethod_test.dart
Tess Strickland d06d627c79 [vm] Remove --[no-]lazy-dispatchers flag.
No client of the VM uses this flag, only tests, and this flag was always
set to false in AOT mode. Thus, remove uses of this flag and instead
always lazily create dispatchers as needed when resolving method names
in JIT mode.

Remove the implicit value of `allow_add` for some Resolver
static methods. For callers that previously depended on the implicit
`true` value (which includes the AOT precompilier), pass `true` for
uses in the compiler and pass `!FLAG_precompiled_mode` for uses in the
runtime. Assert that `allow_add` is false when these methods are invoked
from the precompiled runtime.

Remove Resolver static methods that are no longer used.

TEST=ci

Change-Id: Ib6a7354f7a859e86743c381513a4129c14895753
Cq-Include-Trybots: luci.dart.try:vm-linux-debug-x64-try,vm-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-mac-release-arm64-try,vm-mac-debug-arm64-try,vm-mac-release-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366668
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2024-06-06 10:56:12 +00:00

87 lines
2.7 KiB
Dart

// Copyright (c) 2017, 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";
// Test that noSuchMethod calls behave as expected for dynamic object invocations.
class BaseClass {
final dynamic finalField = "final!";
baz() => "baz!!";
get bla => (() => "bla!!");
}
class ReturnInvocationName extends BaseClass {
var _bar;
ReturnInvocationName(this._bar);
noSuchMethod(Invocation invocation) {
var name = invocation.memberName.toString();
var match = new RegExp(r'Symbol\("([^"]+)"\)').matchAsPrefix(name);
return match != null ? match.group(1) : name;
}
bar() {
return _bar;
}
}
class Foo {}
main() {
dynamic x = new ReturnInvocationName(42);
Expect.equals('final!', x.finalField);
Expect.equals('foo', x.finalField = "foo", 'should call noSuchMethod');
Expect.equals('final!', x.finalField, 'field was not set');
Expect.equals('_prototype', x._prototype);
Expect.equals('_prototype', x._prototype());
Expect.equals('prototype', x.prototype);
Expect.equals('prototype', x.prototype());
Expect.equals('constructor', x.constructor);
Expect.equals('constructor', x.constructor());
Expect.equals('__proto__', x.__proto__);
Expect.equals('__proto__', x.__proto__);
Expect.equals(42, x.bar());
Expect.equals(42, (x.bar)());
Expect.equals('unary-', -x);
Expect.equals('+', x + 42);
Expect.equals('[]', x[4]);
dynamic b = new BaseClass();
Expect.equals('final!', b.finalField);
Expect.throwsNoSuchMethodError(() => b.finalField = "foo");
Expect.equals('final!', b.finalField, 'field was not set');
// Verify that noSuchMethod errors are triggered even when the JS object
// happens to have a matching member name.
dynamic f = new Foo();
Expect.throwsNoSuchMethodError(() => f.prototype);
Expect.throwsNoSuchMethodError(() => f.prototype());
Expect.throwsNoSuchMethodError(() => f.prototype = 42);
Expect.throwsNoSuchMethodError(() => f.constructor);
Expect.throwsNoSuchMethodError(() => f.constructor());
Expect.throwsNoSuchMethodError(() => f.constructor = 42);
Expect.throwsNoSuchMethodError(() => f.__proto__);
// These are valid JS properties but not Dart methods.
Expect.throwsNoSuchMethodError(() => f.toLocaleString);
Expect.throwsNoSuchMethodError(() => f.hasOwnProperty);
f = (int x) {};
// Calls with the wrong number of arguments should be NoSuchMethodErrors.
Expect.throwsNoSuchMethodError(() => f());
Expect.throwsNoSuchMethodError(() => f('hi', '!'));
Expect.throwsNoSuchMethodError(() => f(x: 42));
}