mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 22:40:28 +02:00
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
51 lines
1.1 KiB
JavaScript
51 lines
1.1 KiB
JavaScript
function assert(assertion) {
|
|
if (typeof assertion != "string")
|
|
throw new Error("Invalid assertion.");
|
|
|
|
let result = eval(assertion);
|
|
|
|
if (!result)
|
|
throw new Error("Bad assertion: " + assertion);
|
|
}
|
|
|
|
let calls = 0;
|
|
let getSet = [];
|
|
|
|
function resetTracking()
|
|
{
|
|
calls = 0;
|
|
getSet = [];
|
|
}
|
|
|
|
let getSetProxyReplace = new Proxy(
|
|
{
|
|
replace: function(string, search, replaceWith)
|
|
{
|
|
calls++;
|
|
return string.replace(search, replaceWith);
|
|
}
|
|
}, {
|
|
get: function(o, k)
|
|
{
|
|
getSet.push(k);
|
|
return o[k];
|
|
},
|
|
set: function(o, k, v)
|
|
{
|
|
getSet.push(k);
|
|
o[k] = v;
|
|
}
|
|
});
|
|
|
|
resetTracking();
|
|
let replaceResult = getSetProxyReplace.replace("This is a test", / /g, "_");
|
|
assert('replaceResult == "This_is_a_test"');
|
|
assert('calls === 1')
|
|
assert('getSet == "replace"');
|
|
|
|
resetTracking();
|
|
replaceResult = getSetProxyReplace.replace("This is a test", " ", "_");
|
|
assert('replaceResult == "This_is a test"');
|
|
assert('calls === 1')
|
|
assert('getSet == "replace"');
|