1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/openharmony-third_party_jerryscript

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Это зеркальный репозиторий, синхронизируется ежедневно с исходного репозитория.
Клонировать/Скачать
symbol-replace.js 13 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
Gavin1012 Отправлено 4 лет назад 0c184d9
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
var replace = RegExp.prototype[Symbol.replace];
try {
replace.call (0, "string", "replace");
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
try {
replace.call (new RegExp(), {
toString: () => {
throw "abrupt string"
}
}, "replace");
assert (false);
} catch (e) {
assert (e === "abrupt string");
}
try {
replace.call (new RegExp(), "string", {
toString: () => {
throw "abrupt replace"
}
});
assert (false);
} catch (e) {
assert (e === "abrupt replace");
}
try {
replace.call ({
get global() {
throw "abrupt global"
}
}, "string", "replace");
assert (false);
} catch (e) {
assert (e === "abrupt global");
}
try {
replace.call ({
global: true,
set lastIndex(idx) {
throw "abrupt lastIndex"
}
}, "string", "replace");
assert (false);
} catch (e) {
assert (e === "abrupt lastIndex");
}
try {
replace.call ({
get exec() {
throw "abrupt exec"
}
}, "string", "replace");
assert (false);
} catch (e) {
assert (e === "abrupt exec");
}
try {
replace.call ({
exec: RegExp.prototype.exec
}, "string", "replace");
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
try {
replace.call ({
exec: 42
}, "string", "replace");
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
try {
replace.call ({
exec: () => {
throw "abrupt exec result"
}
}, "string", "replace");
assert (false);
} catch (e) {
assert (e === "abrupt exec result");
}
try {
replace.call ({
exec: () => {
return 1
}
}, "string", "replace");
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
try {
replace.call ({
exec: () => {
return {
get length() {
throw "abrupt result length"
}
}
}
}, "string", "replace");
assert (false);
} catch (e) {
assert (e === "abrupt result length");
}
try {
replace.call ({
global: true,
exec: () => {
return {
length: 1,
get 0() {
throw "abrupt match"
}
}
}
},
"string",
"replace");
assert (false);
} catch (e) {
assert (e === "abrupt match");
}
try {
replace.call ({
global: true,
exec: () => {
return {
length: 1,
get 0() {
return {
toString: () => {
throw "abrupt match toString"
}
}
}
}
}
},
"string",
"replace");
assert (false);
} catch (e) {
assert (e === "abrupt match toString");
}
var result_obj = {
toString: () => {
Object.defineProperty (result_obj, 'toString', {
value: () => {
throw "abrupt match toString delayed";
}
});
return "str";
}
}
var first = true;
try {
replace.call ({
global: true,
exec: () => {
if (!first) {
return null;
}
first = false;
return {
length: 1,
get 0() {
return result_obj;
}
}
}
},
"string",
"replace");
assert (false);
} catch (e) {
assert (e === "abrupt match toString delayed");
}
try {
replace.call ({
global: true,
get lastIndex() {
throw "abrupt lastIndex get"
},
set lastIndex(i) {},
exec: () => {
return {
length: 1,
get 0() {
return {
toString: () => {
return ""
}
}
}
}
}
},
"string",
"replace");
assert (false);
} catch (e) {
assert (e === "abrupt lastIndex get");
}
try {
replace.call ({
global: true,
get lastIndex() {
return {
valueOf: () => {
throw "abrupt lastIndex toNumber"
}
}
},
set lastIndex(i) {},
exec: () => {
return {
length: 1,
get 0() {
return {
toString: () => {
return ""
}
}
}
}
}
},
"string",
"replace");
assert (false);
} catch (e) {
assert (e === "abrupt lastIndex toNumber");
}
var o = {
global: true,
exec: () => {
return {
length: 1,
get 0() {
return {
toString: () => {
return ""
}
}
}
}
}
}
Object.defineProperty (o, 'lastIndex', {
configurable: true,
get: () => {
Object.defineProperty (o, 'lastIndex', {
get: () => {
return {
valueOf: () => {
return 42
}
};
},
set: (i) => {
throw "abrupt lastIndex put";
},
configurable: true
});
return {
valueOf: () => {
return 24
}
};
},
set: (i) => {}
});
try {
replace.call (o,
"string",
"replace");
assert (false);
} catch (e) {
assert (e === "abrupt lastIndex put");
}
o = {
global: true,
exec: () => {
return {
length: 1,
get 0() {
return {
toString: () => {
return ""
}
}
}
}
},
};
Object.defineProperty (o, 'lastIndex', {
get: () => {
Object.defineProperty (o, 'lastIndex', {
value: 0,
writable: false
});
return 0;
},
set: () => {}
});
try {
replace.call (o,
"string",
"replace");
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
o = {
global: true
};
Object.defineProperty (o, 'exec', {
configurable: true,
value: () => {
Object.defineProperty (o, 'exec', {
get: () => {
throw "abrupt exec"
},
set: (v) => {}
});
return {
length: 1,
0: "thisisastring"
}
}
});
try {
replace.call (o,
"string",
"replace");
assert (false);
} catch (e) {
assert (e === "abrupt exec");
}
try {
replace.call ({
exec: () => {
return {
length: 1,
0: "str",
get index() {
throw "abrupt index"
}
}
}
}, "string", "replace");
assert (false);
} catch (e) {
assert (e === "abrupt index");
}
try {
replace.call ({
exec: () => {
return {
length: 1,
0: "str",
get index() {
return {
valueOf: () => {
throw "abrupt index toNumber"
}
}
}
}
}
}, "string", "replace");
assert (false);
} catch (e) {
assert (e === "abrupt index toNumber");
}
try {
replace.call ({
exec: () => {
return {
length: 2,
0: "str",
index: 0,
get 1() {
throw "abrupt capture"
}
}
}
}, "string", "replace");
assert (false);
} catch (e) {
assert (e === "abrupt capture");
}
try {
replace.call ({
exec: () => {
return {
length: 2,
0: "str",
index: 0,
1: {
toString: () => {
throw "abrupt capture toString"
}
}
}
}
}, "string", "replace");
assert (false);
} catch (e) {
assert (e === "abrupt capture toString");
}
try {
replace.call ({
exec: () => {
return {
length: 2,
0: "str",
index: 0,
1: "st"
}
}
}, "string", () => {
throw "abrupt replace"
});
assert (false);
} catch (e) {
assert (e === "abrupt replace");
}
try {
replace.call ({
exec: () => {
return {
length: 2,
0: "str",
index: 0,
1: "st"
}
}
}, "string", () => {
return {
toString: () => {
throw "abrupt replace toString"
}
}
});
assert (false);
} catch (e) {
assert (e === "abrupt replace toString");
}
try {
replace.call (/abc/, "abc", () => {
throw "fastpath abrupt replace"
});
assert (false);
} catch (e) {
assert (e === "fastpath abrupt replace");
}
try {
replace.call (/abc/, "abc", () => {
return {
toString: () => {
throw "fastpath abrupt replace"
}
}
});
assert (false);
} catch (e) {
assert (e === "fastpath abrupt replace");
}
assert (replace.call (/abc/, "abc", "xyz") === "xyz");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "xyz") === "abxyzfg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$$-") === "ab-$-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$&-") === "ab-cde-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$`-") === "ab-ab-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$'-") === "ab-fg-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$0-") === "ab-$0-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$1-") === "ab-c-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$2-") === "ab-d-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$3-") === "ab-d-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$4-") === "ab--fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$5-") === "ab-e-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$6-") === "ab-$6-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$00-") === "ab-$00-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$01-") === "ab-c-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$10-") === "ab-c0-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$99-") === "ab-$99-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "-$$1-") === "ab-$1-fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "$") === "ab$fg");
assert (replace.call (/(c)((d)|(x))(e)/, "abcdefg", "$@") === "ab$@fg");
replace.call (/(c)((d)|(x))(e)/, "abcdefg", function () {
assert (arguments[0] === "cde");
assert (arguments[1] === "c");
assert (arguments[2] === "d");
assert (arguments[3] === "d");
assert (arguments[4] === undefined);
assert (arguments[5] === "e");
assert (arguments[6] === 2);
assert (arguments[7] === "abcdefg");
});
var re = /ab/g;
assert (replace.call (re, "-ab-ab-ab-ab-", "cd") === "-cd-cd-cd-cd-");
assert (re.lastIndex === 0);
re.lastIndex = 5;
assert (replace.call (re, "-ab-ab-ab-ab-", "cd") === "-cd-cd-cd-cd-");
assert (re.lastIndex === 0);
assert (replace.call (/(?:)/g, "string", "Duck") === "DucksDucktDuckrDuckiDucknDuckgDuck");
class Regexplike {
constructor() {
this.index = 0;
this.global = true;
}
exec() {
if (this.index > 0) {
return null;
}
this.index = 39;
var result = {
length: 1,
0: "Duck",
index: this.index
};
return result;
}
}
re = new Regexplike();
/* Well-behaved RegExp-like object. */
assert (replace.call (re, "What have you brought upon this cursed land", "$&") === "What have you brought upon this cursed Duck");
var replace_count = 0;
function replacer() {
replace_count++;
return arguments[0];
}
re.index = 0;
re.exec = function () {
if (this.index > 3) {
return null;
}
var result = {
length: 1,
0: "Duck",
index: this.index++
};
return result;
}
/* Mis-behaving RegExp-like object, replace function is called on each match, but the result is ignored for inconsistent matches. */
assert (replace.call (re, "Badger", replacer) === "Ducker");
assert (replace_count === 4);
re.index = 0;
assert (replace.call (re, "Badger", "Ord") === "Order");
try {
replace.call (RegExp.prototype, "string", "replace");
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
assert(replace.call({ exec : ( ) => { return { } } }, 'һ', "a") === "a");
assert(replace.call({ exec : ( ) => { return { } } }, 'һһһһһһһһһ', "a") === "a");
assert(replace.call({ exec : ( ) => { return { } } }, 'һһһһһһһһһһ', "a") === "");
/* Object with custom @@replace method */
var o = {}
o[Symbol.replace] = function () {
return "Duck"
};
assert ("string".replace (o, "Mallard") === "Duck");
o[Symbol.replace] = 42;
try {
"string".replace (o, "Duck");
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
Object.defineProperty (o, Symbol.replace, {
get: () => {
throw "abrupt @@replace get"
},
set: (v) => {}
});
try {
"string".replace (o, "Duck");
assert (false);
} catch (e) {
assert (e === "abrupt @@replace get");
}
o = {};
o[Symbol.replace] = function () {
throw "abrupt @@replace"
};
try {
"string".replace (o, "str");
assert (false);
} catch (e) {
assert (e === "abrupt @@replace")
}
class Regexplike2 {
exec() {
return {}
}
}
re = new Regexplike2();
assert (replace.call (re, "1") === "undefined");

Комментарий ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/openharmony-third_party_jerryscript.git
git@gitlife.ru:oschina-mirror/openharmony-third_party_jerryscript.git
oschina-mirror
openharmony-third_party_jerryscript
openharmony-third_party_jerryscript
OpenHarmony-v5.0.2-Release