4d53833f35
Prior to this CL we still implemented a HasProperty-GetProperty sequence when accessing named captures in GetSubstitution. This was briefly part of the spec (we also threw an exception when the property was not present), but since late 2017 the GetProperty call has been unconditional. See https://tc39.es/ecma262/#sec-getsubstitution. Bug: v8:10513 Change-Id: Id82c06958b0b0feffc6eede580b99ab8676a0dae Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2195821 Auto-Submit: Jakob Gruber <jgruber@chromium.org> Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org> Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Cr-Commit-Position: refs/heads/master@{#67733}
26 lines
641 B
JavaScript
26 lines
641 B
JavaScript
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
const access_log = [];
|
|
const handler = {
|
|
get: function(obj, prop) {
|
|
access_log.push(prop);
|
|
return prop in obj ? obj[prop] : "z";
|
|
}
|
|
};
|
|
|
|
class ProxiedGroupRegExp extends RegExp {
|
|
exec(s) {
|
|
var result = super.exec(s);
|
|
if (result) {
|
|
result.groups = new Proxy(result.groups, handler);
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
|
|
let re = new ProxiedGroupRegExp("(?<x>.)");
|
|
assertEquals("a z", "a".replace(re, "$<x> $<y>"));
|
|
assertEquals(["x", "y"], access_log);
|