v8/test/mjsunit/es6/regexp-tostring.js
yangguo 269840c496 [regexp] Fix RegExp.prototype.toString.
Initial fix was simply wrong.

R=verwaest@chromium.org
BUG=v8:4524
LOG=N

Review URL: https://codereview.chromium.org/1688163003

Cr-Commit-Position: refs/heads/master@{#33896}
2016-02-11 13:23:20 +00:00

47 lines
981 B
JavaScript

// Copyright 2016 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.
var log = [];
var fake =
{
get source() {
log.push("p");
return {
toString: function() {
log.push("ps");
return "pattern";
}
};
},
get flags() {
log.push("f");
return {
toString: function() {
log.push("fs");
return "flags";
}
};
}
}
function testThrows(x) {
try {
RegExp.prototype.toString.call(x);
} catch (e) {
assertTrue(/incompatible receiver/.test(e.message));
return;
}
assertUnreachable();
}
testThrows(1);
testThrows(null);
Number.prototype.source = "a";
Number.prototype.flags = "b";
testThrows(1);
assertEquals("/pattern/flags", RegExp.prototype.toString.call(fake));
assertEquals(["p", "ps", "f", "fs"], log);