|
Lines 41-46
a/Source/JavaScriptCore/runtime/StringPrototype.cpp_sec1
|
| 41 |
#include "RegExpConstructor.h" |
41 |
#include "RegExpConstructor.h" |
| 42 |
#include "RegExpMatchesArray.h" |
42 |
#include "RegExpMatchesArray.h" |
| 43 |
#include "RegExpObject.h" |
43 |
#include "RegExpObject.h" |
|
|
44 |
#include "RegExpPrototype.h" |
| 44 |
#include <algorithm> |
45 |
#include <algorithm> |
| 45 |
#include <wtf/ASCIICType.h> |
46 |
#include <wtf/ASCIICType.h> |
| 46 |
#include <wtf/MathExtras.h> |
47 |
#include <wtf/MathExtras.h> |
|
Lines 185-644
static inline JSString* jsSubstring(ExecState* exec, JSValue originalValue, cons
a/Source/JavaScriptCore/runtime/StringPrototype.cpp_sec2
|
| 185 |
return jsSubstring(exec, string, offset, length); |
186 |
return jsSubstring(exec, string, offset, length); |
| 186 |
} |
187 |
} |
| 187 |
|
188 |
|
| 188 |
static NEVER_INLINE String substituteBackreferencesSlow(StringView replacement, StringView source, const int* ovector, RegExp* reg, size_t i) |
189 |
static inline EncodedJSValue replaceUsingStringSearch(ExecState* exec, JSString* jsString, JSValue searchValue, JSValue replaceValue) |
| 189 |
{ |
|
|
| 190 |
StringBuilder substitutedReplacement; |
| 191 |
int offset = 0; |
| 192 |
do { |
| 193 |
if (i + 1 == replacement.length()) |
| 194 |
break; |
| 195 |
|
| 196 |
UChar ref = replacement[i + 1]; |
| 197 |
if (ref == '$') { |
| 198 |
// "$$" -> "$" |
| 199 |
++i; |
| 200 |
substitutedReplacement.append(replacement.substring(offset, i - offset)); |
| 201 |
offset = i + 1; |
| 202 |
continue; |
| 203 |
} |
| 204 |
|
| 205 |
int backrefStart; |
| 206 |
int backrefLength; |
| 207 |
int advance = 0; |
| 208 |
if (ref == '&') { |
| 209 |
backrefStart = ovector[0]; |
| 210 |
backrefLength = ovector[1] - backrefStart; |
| 211 |
} else if (ref == '`') { |
| 212 |
backrefStart = 0; |
| 213 |
backrefLength = ovector[0]; |
| 214 |
} else if (ref == '\'') { |
| 215 |
backrefStart = ovector[1]; |
| 216 |
backrefLength = source.length() - backrefStart; |
| 217 |
} else if (reg && ref >= '0' && ref <= '9') { |
| 218 |
// 1- and 2-digit back references are allowed |
| 219 |
unsigned backrefIndex = ref - '0'; |
| 220 |
if (backrefIndex > reg->numSubpatterns()) |
| 221 |
continue; |
| 222 |
if (replacement.length() > i + 2) { |
| 223 |
ref = replacement[i + 2]; |
| 224 |
if (ref >= '0' && ref <= '9') { |
| 225 |
backrefIndex = 10 * backrefIndex + ref - '0'; |
| 226 |
if (backrefIndex > reg->numSubpatterns()) |
| 227 |
backrefIndex = backrefIndex / 10; // Fall back to the 1-digit reference |
| 228 |
else |
| 229 |
advance = 1; |
| 230 |
} |
| 231 |
} |
| 232 |
if (!backrefIndex) |
| 233 |
continue; |
| 234 |
backrefStart = ovector[2 * backrefIndex]; |
| 235 |
backrefLength = ovector[2 * backrefIndex + 1] - backrefStart; |
| 236 |
} else |
| 237 |
continue; |
| 238 |
|
| 239 |
if (i - offset) |
| 240 |
substitutedReplacement.append(replacement.substring(offset, i - offset)); |
| 241 |
i += 1 + advance; |
| 242 |
offset = i + 1; |
| 243 |
if (backrefStart >= 0) |
| 244 |
substitutedReplacement.append(source.substring(backrefStart, backrefLength)); |
| 245 |
} while ((i = replacement.find('$', i + 1)) != notFound); |
| 246 |
|
| 247 |
if (replacement.length() - offset) |
| 248 |
substitutedReplacement.append(replacement.substring(offset)); |
| 249 |
|
| 250 |
return substitutedReplacement.toString(); |
| 251 |
} |
| 252 |
|
| 253 |
static inline String substituteBackreferences(const String& replacement, StringView source, const int* ovector, RegExp* reg) |
| 254 |
{ |
| 255 |
size_t i = replacement.find('$'); |
| 256 |
if (UNLIKELY(i != notFound)) |
| 257 |
return substituteBackreferencesSlow(replacement, source, ovector, reg, i); |
| 258 |
|
| 259 |
return replacement; |
| 260 |
} |
| 261 |
|
| 262 |
struct StringRange { |
| 263 |
StringRange(int pos, int len) |
| 264 |
: position(pos) |
| 265 |
, length(len) |
| 266 |
{ |
| 267 |
} |
| 268 |
|
| 269 |
StringRange() |
| 270 |
{ |
| 271 |
} |
| 272 |
|
| 273 |
int position; |
| 274 |
int length; |
| 275 |
}; |
| 276 |
|
| 277 |
static ALWAYS_INLINE JSValue jsSpliceSubstrings(ExecState* exec, JSString* sourceVal, const String& source, const StringRange* substringRanges, int rangeCount) |
| 278 |
{ |
| 279 |
if (rangeCount == 1) { |
| 280 |
int sourceSize = source.length(); |
| 281 |
int position = substringRanges[0].position; |
| 282 |
int length = substringRanges[0].length; |
| 283 |
if (position <= 0 && length >= sourceSize) |
| 284 |
return sourceVal; |
| 285 |
// We could call String::substringSharingImpl(), but this would result in redundant checks. |
| 286 |
return jsString(exec, StringImpl::createSubstringSharingImpl(source.impl(), std::max(0, position), std::min(sourceSize, length))); |
| 287 |
} |
| 288 |
|
| 289 |
int totalLength = 0; |
| 290 |
for (int i = 0; i < rangeCount; i++) |
| 291 |
totalLength += substringRanges[i].length; |
| 292 |
|
| 293 |
if (!totalLength) |
| 294 |
return jsEmptyString(exec); |
| 295 |
|
| 296 |
if (source.is8Bit()) { |
| 297 |
LChar* buffer; |
| 298 |
const LChar* sourceData = source.characters8(); |
| 299 |
RefPtr<StringImpl> impl = StringImpl::tryCreateUninitialized(totalLength, buffer); |
| 300 |
if (!impl) |
| 301 |
return throwOutOfMemoryError(exec); |
| 302 |
|
| 303 |
int bufferPos = 0; |
| 304 |
for (int i = 0; i < rangeCount; i++) { |
| 305 |
if (int srcLen = substringRanges[i].length) { |
| 306 |
StringImpl::copyChars(buffer + bufferPos, sourceData + substringRanges[i].position, srcLen); |
| 307 |
bufferPos += srcLen; |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
return jsString(exec, impl.release()); |
| 312 |
} |
| 313 |
|
| 314 |
UChar* buffer; |
| 315 |
const UChar* sourceData = source.characters16(); |
| 316 |
|
| 317 |
RefPtr<StringImpl> impl = StringImpl::tryCreateUninitialized(totalLength, buffer); |
| 318 |
if (!impl) |
| 319 |
return throwOutOfMemoryError(exec); |
| 320 |
|
| 321 |
int bufferPos = 0; |
| 322 |
for (int i = 0; i < rangeCount; i++) { |
| 323 |
if (int srcLen = substringRanges[i].length) { |
| 324 |
StringImpl::copyChars(buffer + bufferPos, sourceData + substringRanges[i].position, srcLen); |
| 325 |
bufferPos += srcLen; |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
return jsString(exec, impl.release()); |
| 330 |
} |
| 331 |
|
| 332 |
static ALWAYS_INLINE JSValue jsSpliceSubstringsWithSeparators(ExecState* exec, JSString* sourceVal, const String& source, const StringRange* substringRanges, int rangeCount, const String* separators, int separatorCount) |
| 333 |
{ |
| 334 |
if (rangeCount == 1 && separatorCount == 0) { |
| 335 |
int sourceSize = source.length(); |
| 336 |
int position = substringRanges[0].position; |
| 337 |
int length = substringRanges[0].length; |
| 338 |
if (position <= 0 && length >= sourceSize) |
| 339 |
return sourceVal; |
| 340 |
// We could call String::substringSharingImpl(), but this would result in redundant checks. |
| 341 |
return jsString(exec, StringImpl::createSubstringSharingImpl(source.impl(), std::max(0, position), std::min(sourceSize, length))); |
| 342 |
} |
| 343 |
|
| 344 |
Checked<int, RecordOverflow> totalLength = 0; |
| 345 |
bool allSeparators8Bit = true; |
| 346 |
for (int i = 0; i < rangeCount; i++) |
| 347 |
totalLength += substringRanges[i].length; |
| 348 |
for (int i = 0; i < separatorCount; i++) { |
| 349 |
totalLength += separators[i].length(); |
| 350 |
if (separators[i].length() && !separators[i].is8Bit()) |
| 351 |
allSeparators8Bit = false; |
| 352 |
} |
| 353 |
if (totalLength.hasOverflowed()) |
| 354 |
return throwOutOfMemoryError(exec); |
| 355 |
|
| 356 |
if (!totalLength) |
| 357 |
return jsEmptyString(exec); |
| 358 |
|
| 359 |
if (source.is8Bit() && allSeparators8Bit) { |
| 360 |
LChar* buffer; |
| 361 |
const LChar* sourceData = source.characters8(); |
| 362 |
|
| 363 |
RefPtr<StringImpl> impl = StringImpl::tryCreateUninitialized(totalLength.unsafeGet(), buffer); |
| 364 |
if (!impl) |
| 365 |
return throwOutOfMemoryError(exec); |
| 366 |
|
| 367 |
int maxCount = std::max(rangeCount, separatorCount); |
| 368 |
int bufferPos = 0; |
| 369 |
for (int i = 0; i < maxCount; i++) { |
| 370 |
if (i < rangeCount) { |
| 371 |
if (int srcLen = substringRanges[i].length) { |
| 372 |
StringImpl::copyChars(buffer + bufferPos, sourceData + substringRanges[i].position, srcLen); |
| 373 |
bufferPos += srcLen; |
| 374 |
} |
| 375 |
} |
| 376 |
if (i < separatorCount) { |
| 377 |
if (int sepLen = separators[i].length()) { |
| 378 |
StringImpl::copyChars(buffer + bufferPos, separators[i].characters8(), sepLen); |
| 379 |
bufferPos += sepLen; |
| 380 |
} |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
return jsString(exec, impl.release()); |
| 385 |
} |
| 386 |
|
| 387 |
UChar* buffer; |
| 388 |
RefPtr<StringImpl> impl = StringImpl::tryCreateUninitialized(totalLength.unsafeGet(), buffer); |
| 389 |
if (!impl) |
| 390 |
return throwOutOfMemoryError(exec); |
| 391 |
|
| 392 |
int maxCount = std::max(rangeCount, separatorCount); |
| 393 |
int bufferPos = 0; |
| 394 |
for (int i = 0; i < maxCount; i++) { |
| 395 |
if (i < rangeCount) { |
| 396 |
if (int srcLen = substringRanges[i].length) { |
| 397 |
if (source.is8Bit()) |
| 398 |
StringImpl::copyChars(buffer + bufferPos, source.characters8() + substringRanges[i].position, srcLen); |
| 399 |
else |
| 400 |
StringImpl::copyChars(buffer + bufferPos, source.characters16() + substringRanges[i].position, srcLen); |
| 401 |
bufferPos += srcLen; |
| 402 |
} |
| 403 |
} |
| 404 |
if (i < separatorCount) { |
| 405 |
if (int sepLen = separators[i].length()) { |
| 406 |
if (separators[i].is8Bit()) |
| 407 |
StringImpl::copyChars(buffer + bufferPos, separators[i].characters8(), sepLen); |
| 408 |
else |
| 409 |
StringImpl::copyChars(buffer + bufferPos, separators[i].characters16(), sepLen); |
| 410 |
bufferPos += sepLen; |
| 411 |
} |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
return jsString(exec, impl.release()); |
| 416 |
} |
| 417 |
|
| 418 |
static NEVER_INLINE EncodedJSValue removeUsingRegExpSearch(ExecState* exec, JSString* string, const String& source, RegExp* regExp) |
| 419 |
{ |
| 420 |
size_t lastIndex = 0; |
| 421 |
unsigned startPosition = 0; |
| 422 |
|
| 423 |
Vector<StringRange, 16> sourceRanges; |
| 424 |
VM* vm = &exec->vm(); |
| 425 |
RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor(); |
| 426 |
unsigned sourceLen = source.length(); |
| 427 |
|
| 428 |
while (true) { |
| 429 |
MatchResult result = regExpConstructor->performMatch(*vm, regExp, string, source, startPosition); |
| 430 |
if (!result) |
| 431 |
break; |
| 432 |
|
| 433 |
if (lastIndex < result.start) |
| 434 |
sourceRanges.append(StringRange(lastIndex, result.start - lastIndex)); |
| 435 |
|
| 436 |
lastIndex = result.end; |
| 437 |
startPosition = lastIndex; |
| 438 |
|
| 439 |
// special case of empty match |
| 440 |
if (result.empty()) { |
| 441 |
startPosition++; |
| 442 |
if (startPosition > sourceLen) |
| 443 |
break; |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
if (!lastIndex) |
| 448 |
return JSValue::encode(string); |
| 449 |
|
| 450 |
if (static_cast<unsigned>(lastIndex) < sourceLen) |
| 451 |
sourceRanges.append(StringRange(lastIndex, sourceLen - lastIndex)); |
| 452 |
|
| 453 |
return JSValue::encode(jsSpliceSubstrings(exec, string, source, sourceRanges.data(), sourceRanges.size())); |
| 454 |
} |
| 455 |
|
| 456 |
static NEVER_INLINE EncodedJSValue replaceUsingRegExpSearch(ExecState* exec, JSString* string, JSValue searchValue) |
| 457 |
{ |
| 458 |
JSValue replaceValue = exec->argument(1); |
| 459 |
String replacementString; |
| 460 |
CallData callData; |
| 461 |
CallType callType = getCallData(replaceValue, callData); |
| 462 |
if (callType == CallTypeNone) |
| 463 |
replacementString = replaceValue.toString(exec)->value(exec); |
| 464 |
|
| 465 |
const String& source = string->value(exec); |
| 466 |
unsigned sourceLen = source.length(); |
| 467 |
if (exec->hadException()) |
| 468 |
return JSValue::encode(JSValue()); |
| 469 |
RegExpObject* regExpObject = asRegExpObject(searchValue); |
| 470 |
RegExp* regExp = regExpObject->regExp(); |
| 471 |
bool global = regExp->global(); |
| 472 |
|
| 473 |
if (global) { |
| 474 |
// ES5.1 15.5.4.10 step 8.a. |
| 475 |
regExpObject->setLastIndex(exec, 0); |
| 476 |
if (exec->hadException()) |
| 477 |
return JSValue::encode(JSValue()); |
| 478 |
|
| 479 |
if (callType == CallTypeNone && !replacementString.length()) |
| 480 |
return removeUsingRegExpSearch(exec, string, source, regExp); |
| 481 |
} |
| 482 |
|
| 483 |
RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor(); |
| 484 |
|
| 485 |
size_t lastIndex = 0; |
| 486 |
unsigned startPosition = 0; |
| 487 |
|
| 488 |
Vector<StringRange, 16> sourceRanges; |
| 489 |
Vector<String, 16> replacements; |
| 490 |
|
| 491 |
// This is either a loop (if global is set) or a one-way (if not). |
| 492 |
if (global && callType == CallTypeJS) { |
| 493 |
// regExp->numSubpatterns() + 1 for pattern args, + 2 for match start and string |
| 494 |
int argCount = regExp->numSubpatterns() + 1 + 2; |
| 495 |
JSFunction* func = jsCast<JSFunction*>(replaceValue); |
| 496 |
CachedCall cachedCall(exec, func, argCount); |
| 497 |
if (exec->hadException()) |
| 498 |
return JSValue::encode(jsNull()); |
| 499 |
VM* vm = &exec->vm(); |
| 500 |
if (source.is8Bit()) { |
| 501 |
while (true) { |
| 502 |
int* ovector; |
| 503 |
MatchResult result = regExpConstructor->performMatch(*vm, regExp, string, source, startPosition, &ovector); |
| 504 |
if (!result) |
| 505 |
break; |
| 506 |
|
| 507 |
sourceRanges.append(StringRange(lastIndex, result.start - lastIndex)); |
| 508 |
|
| 509 |
unsigned i = 0; |
| 510 |
for (; i < regExp->numSubpatterns() + 1; ++i) { |
| 511 |
int matchStart = ovector[i * 2]; |
| 512 |
int matchLen = ovector[i * 2 + 1] - matchStart; |
| 513 |
|
| 514 |
if (matchStart < 0) |
| 515 |
cachedCall.setArgument(i, jsUndefined()); |
| 516 |
else |
| 517 |
cachedCall.setArgument(i, jsSubstring8(vm, source, matchStart, matchLen)); |
| 518 |
} |
| 519 |
|
| 520 |
cachedCall.setArgument(i++, jsNumber(result.start)); |
| 521 |
cachedCall.setArgument(i++, string); |
| 522 |
|
| 523 |
cachedCall.setThis(jsUndefined()); |
| 524 |
JSValue jsResult = cachedCall.call(); |
| 525 |
replacements.append(jsResult.toString(exec)->value(exec)); |
| 526 |
if (exec->hadException()) |
| 527 |
break; |
| 528 |
|
| 529 |
lastIndex = result.end; |
| 530 |
startPosition = lastIndex; |
| 531 |
|
| 532 |
// special case of empty match |
| 533 |
if (result.empty()) { |
| 534 |
startPosition++; |
| 535 |
if (startPosition > sourceLen) |
| 536 |
break; |
| 537 |
} |
| 538 |
} |
| 539 |
} else { |
| 540 |
while (true) { |
| 541 |
int* ovector; |
| 542 |
MatchResult result = regExpConstructor->performMatch(*vm, regExp, string, source, startPosition, &ovector); |
| 543 |
if (!result) |
| 544 |
break; |
| 545 |
|
| 546 |
sourceRanges.append(StringRange(lastIndex, result.start - lastIndex)); |
| 547 |
|
| 548 |
unsigned i = 0; |
| 549 |
for (; i < regExp->numSubpatterns() + 1; ++i) { |
| 550 |
int matchStart = ovector[i * 2]; |
| 551 |
int matchLen = ovector[i * 2 + 1] - matchStart; |
| 552 |
|
| 553 |
if (matchStart < 0) |
| 554 |
cachedCall.setArgument(i, jsUndefined()); |
| 555 |
else |
| 556 |
cachedCall.setArgument(i, jsSubstring(vm, source, matchStart, matchLen)); |
| 557 |
} |
| 558 |
|
| 559 |
cachedCall.setArgument(i++, jsNumber(result.start)); |
| 560 |
cachedCall.setArgument(i++, string); |
| 561 |
|
| 562 |
cachedCall.setThis(jsUndefined()); |
| 563 |
JSValue jsResult = cachedCall.call(); |
| 564 |
replacements.append(jsResult.toString(exec)->value(exec)); |
| 565 |
if (exec->hadException()) |
| 566 |
break; |
| 567 |
|
| 568 |
lastIndex = result.end; |
| 569 |
startPosition = lastIndex; |
| 570 |
|
| 571 |
// special case of empty match |
| 572 |
if (result.empty()) { |
| 573 |
startPosition++; |
| 574 |
if (startPosition > sourceLen) |
| 575 |
break; |
| 576 |
} |
| 577 |
} |
| 578 |
} |
| 579 |
} else { |
| 580 |
VM* vm = &exec->vm(); |
| 581 |
do { |
| 582 |
int* ovector; |
| 583 |
MatchResult result = regExpConstructor->performMatch(*vm, regExp, string, source, startPosition, &ovector); |
| 584 |
if (!result) |
| 585 |
break; |
| 586 |
|
| 587 |
if (callType != CallTypeNone) { |
| 588 |
sourceRanges.append(StringRange(lastIndex, result.start - lastIndex)); |
| 589 |
|
| 590 |
MarkedArgumentBuffer args; |
| 591 |
|
| 592 |
for (unsigned i = 0; i < regExp->numSubpatterns() + 1; ++i) { |
| 593 |
int matchStart = ovector[i * 2]; |
| 594 |
int matchLen = ovector[i * 2 + 1] - matchStart; |
| 595 |
|
| 596 |
if (matchStart < 0) |
| 597 |
args.append(jsUndefined()); |
| 598 |
else |
| 599 |
args.append(jsSubstring(exec, source, matchStart, matchLen)); |
| 600 |
} |
| 601 |
|
| 602 |
args.append(jsNumber(result.start)); |
| 603 |
args.append(string); |
| 604 |
|
| 605 |
replacements.append(call(exec, replaceValue, callType, callData, jsUndefined(), args).toString(exec)->value(exec)); |
| 606 |
if (exec->hadException()) |
| 607 |
break; |
| 608 |
} else { |
| 609 |
int replLen = replacementString.length(); |
| 610 |
if (lastIndex < result.start || replLen) { |
| 611 |
sourceRanges.append(StringRange(lastIndex, result.start - lastIndex)); |
| 612 |
|
| 613 |
if (replLen) |
| 614 |
replacements.append(substituteBackreferences(replacementString, source, ovector, regExp)); |
| 615 |
else |
| 616 |
replacements.append(String()); |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
lastIndex = result.end; |
| 621 |
startPosition = lastIndex; |
| 622 |
|
| 623 |
// special case of empty match |
| 624 |
if (result.empty()) { |
| 625 |
startPosition++; |
| 626 |
if (startPosition > sourceLen) |
| 627 |
break; |
| 628 |
} |
| 629 |
} while (global); |
| 630 |
} |
| 631 |
|
| 632 |
if (!lastIndex && replacements.isEmpty()) |
| 633 |
return JSValue::encode(string); |
| 634 |
|
| 635 |
if (static_cast<unsigned>(lastIndex) < sourceLen) |
| 636 |
sourceRanges.append(StringRange(lastIndex, sourceLen - lastIndex)); |
| 637 |
|
| 638 |
return JSValue::encode(jsSpliceSubstringsWithSeparators(exec, string, source, sourceRanges.data(), sourceRanges.size(), replacements.data(), replacements.size())); |
| 639 |
} |
| 640 |
|
| 641 |
static inline EncodedJSValue replaceUsingStringSearch(ExecState* exec, JSString* jsString, JSValue searchValue) |
| 642 |
{ |
190 |
{ |
| 643 |
const String& string = jsString->value(exec); |
191 |
const String& string = jsString->value(exec); |
| 644 |
String searchString = searchValue.toString(exec)->value(exec); |
192 |
String searchString = searchValue.toString(exec)->value(exec); |
|
Lines 650-656
static inline EncodedJSValue replaceUsingStringSearch(ExecState* exec, JSString*
a/Source/JavaScriptCore/runtime/StringPrototype.cpp_sec3
|
| 650 |
if (matchStart == notFound) |
198 |
if (matchStart == notFound) |
| 651 |
return JSValue::encode(jsString); |
199 |
return JSValue::encode(jsString); |
| 652 |
|
200 |
|
| 653 |
JSValue replaceValue = exec->argument(1); |
|
|
| 654 |
CallData callData; |
201 |
CallData callData; |
| 655 |
CallType callType = getCallData(replaceValue, callData); |
202 |
CallType callType = getCallData(replaceValue, callData); |
| 656 |
if (callType != CallTypeNone) { |
203 |
if (callType != CallTypeNone) { |
|
Lines 758-769
EncodedJSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState* exec)
a/Source/JavaScriptCore/runtime/StringPrototype.cpp_sec4
|
| 758 |
JSValue thisValue = exec->thisValue(); |
305 |
JSValue thisValue = exec->thisValue(); |
| 759 |
if (!checkObjectCoercible(thisValue)) |
306 |
if (!checkObjectCoercible(thisValue)) |
| 760 |
return throwVMTypeError(exec); |
307 |
return throwVMTypeError(exec); |
| 761 |
JSString* string = thisValue.toString(exec); |
|
|
| 762 |
JSValue searchValue = exec->argument(0); |
308 |
JSValue searchValue = exec->argument(0); |
|
|
309 |
JSValue replaceValue = exec->argument(1); |
| 310 |
|
| 311 |
if (!searchValue.isUndefinedOrNull()) { |
| 312 |
JSValue replaceFunction = searchValue.get(exec, exec->propertyNames().replaceSymbol); |
| 313 |
if (exec->hadException()) |
| 314 |
return JSValue::encode(jsUndefined()); |
| 315 |
|
| 316 |
if (!replaceFunction.isUndefinedOrNull()) { |
| 317 |
CallData callData; |
| 318 |
CallType callType = getCallData(replaceFunction, callData); |
| 319 |
if (callType == CallTypeNone) |
| 320 |
return throwVMTypeError(exec, "Symbol.replace on the first argument of String.prototype.replace was not a function"); |
| 321 |
|
| 322 |
MarkedArgumentBuffer callArgs; |
| 323 |
callArgs.append(thisValue); |
| 324 |
callArgs.append(replaceValue); |
| 325 |
return JSValue::encode(call(exec, replaceFunction, callType, callData, searchValue, callArgs)); |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
JSString* string = thisValue.toString(exec); |
| 330 |
if (exec->hadException()) |
| 331 |
return JSValue::encode(jsUndefined()); |
| 763 |
|
332 |
|
| 764 |
if (searchValue.inherits(RegExpObject::info())) |
333 |
return replaceUsingStringSearch(exec, string, searchValue, replaceValue); |
| 765 |
return replaceUsingRegExpSearch(exec, string, searchValue); |
|
|
| 766 |
return replaceUsingStringSearch(exec, string, searchValue); |
| 767 |
} |
334 |
} |
| 768 |
|
335 |
|
| 769 |
EncodedJSValue JSC_HOST_CALL stringProtoFuncToString(ExecState* exec) |
336 |
EncodedJSValue JSC_HOST_CALL stringProtoFuncToString(ExecState* exec) |