|
|
|
Lines 366-381
regexp_toString_impl(JSContext *cx, Call
|
Link Here
|
|---|
|
| 366 |
|
366 |
|
| 367 |
static bool |
367 |
static bool |
| 368 |
regexp_toString(JSContext *cx, unsigned argc, Value *vp) |
368 |
regexp_toString(JSContext *cx, unsigned argc, Value *vp) |
| 369 |
{ |
369 |
{ |
| 370 |
CallArgs args = CallArgsFromVp(argc, vp); |
370 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 371 |
return CallNonGenericMethod<IsRegExp, regexp_toString_impl>(cx, args); |
371 |
return CallNonGenericMethod<IsRegExp, regexp_toString_impl>(cx, args); |
| 372 |
} |
372 |
} |
| 373 |
|
373 |
|
|
|
374 |
/* ES6 draft rev29 21.2.5.3 RegExp.prototype.flags */ |
| 375 |
bool |
| 376 |
regexp_flags(JSContext *cx, unsigned argc, JS::Value *vp) |
| 377 |
{ |
| 378 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 379 |
|
| 380 |
/* Steps 1-2. */ |
| 381 |
if (!args.thisv().isObject()) { |
| 382 |
char *bytes = DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, args.thisv(), NullPtr()); |
| 383 |
if (!bytes) |
| 384 |
return false; |
| 385 |
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_UNEXPECTED_TYPE, |
| 386 |
bytes, "not an object"); |
| 387 |
js_free(bytes); |
| 388 |
return false; |
| 389 |
} |
| 390 |
RootedObject thisObj(cx, &args.thisv().toObject()); |
| 391 |
|
| 392 |
/* Step 3. */ |
| 393 |
StringBuffer sb(cx); |
| 394 |
|
| 395 |
/* Steps 4-6. */ |
| 396 |
RootedValue global(cx); |
| 397 |
if (!JSObject::getProperty(cx, thisObj, thisObj, cx->names().global, &global)) |
| 398 |
return false; |
| 399 |
if (ToBoolean(global) && !sb.append('g')) |
| 400 |
return false; |
| 401 |
|
| 402 |
/* Steps 7-9. */ |
| 403 |
RootedValue ignoreCase(cx); |
| 404 |
if (!JSObject::getProperty(cx, thisObj, thisObj, cx->names().ignoreCase, &ignoreCase)) |
| 405 |
return false; |
| 406 |
if (ToBoolean(ignoreCase) && !sb.append('i')) |
| 407 |
return false; |
| 408 |
|
| 409 |
/* Steps 10-12. */ |
| 410 |
RootedValue multiline(cx); |
| 411 |
if (!JSObject::getProperty(cx, thisObj, thisObj, cx->names().multiline, &multiline)) |
| 412 |
return false; |
| 413 |
if (ToBoolean(multiline) && !sb.append('m')) |
| 414 |
return false; |
| 415 |
|
| 416 |
/* Steps 13-15. */ |
| 417 |
RootedValue sticky(cx); |
| 418 |
if (!JSObject::getProperty(cx, thisObj, thisObj, cx->names().sticky, &sticky)) |
| 419 |
return false; |
| 420 |
if (ToBoolean(sticky) && !sb.append('y')) |
| 421 |
return false; |
| 422 |
|
| 423 |
/* Steps 16-18. */ |
| 424 |
RootedValue unicode(cx); |
| 425 |
if (!JSObject::getProperty(cx, thisObj, thisObj, cx->names().unicode, &unicode)) |
| 426 |
return false; |
| 427 |
if (ToBoolean(unicode) && !sb.append('u')) |
| 428 |
return false; |
| 429 |
|
| 430 |
/* Step 19. */ |
| 431 |
args.rval().setString(sb.finishString()); |
| 432 |
return true; |
| 433 |
} |
| 434 |
|
| 435 |
static const JSPropertySpec regexp_properties[] = { |
| 436 |
JS_PSG("flags", regexp_flags, 0), |
| 437 |
JS_PS_END |
| 438 |
}; |
| 439 |
|
| 374 |
static const JSFunctionSpec regexp_methods[] = { |
440 |
static const JSFunctionSpec regexp_methods[] = { |
| 375 |
#if JS_HAS_TOSOURCE |
441 |
#if JS_HAS_TOSOURCE |
| 376 |
JS_FN(js_toSource_str, regexp_toString, 0,0), |
442 |
JS_FN(js_toSource_str, regexp_toString, 0,0), |
| 377 |
#endif |
443 |
#endif |
| 378 |
JS_FN(js_toString_str, regexp_toString, 0,0), |
444 |
JS_FN(js_toString_str, regexp_toString, 0,0), |
| 379 |
JS_FN("compile", regexp_compile, 2,0), |
445 |
JS_FN("compile", regexp_compile, 2,0), |
| 380 |
JS_FN("exec", regexp_exec, 1,0), |
446 |
JS_FN("exec", regexp_exec, 1,0), |
| 381 |
JS_FN("test", regexp_test, 1,0), |
447 |
JS_FN("test", regexp_test, 1,0), |
|
Lines 512-528
js_InitRegExpClass(JSContext *cx, Handle
|
Link Here
|
|---|
|
| 512 |
return nullptr; |
578 |
return nullptr; |
| 513 |
proto->NativeObject::setPrivate(nullptr); |
579 |
proto->NativeObject::setPrivate(nullptr); |
| 514 |
|
580 |
|
| 515 |
HandlePropertyName empty = cx->names().empty; |
581 |
HandlePropertyName empty = cx->names().empty; |
| 516 |
RegExpObjectBuilder builder(cx, proto); |
582 |
RegExpObjectBuilder builder(cx, proto); |
| 517 |
if (!builder.build(empty, RegExpFlag(0))) |
583 |
if (!builder.build(empty, RegExpFlag(0))) |
| 518 |
return nullptr; |
584 |
return nullptr; |
| 519 |
|
585 |
|
| 520 |
if (!DefinePropertiesAndFunctions(cx, proto, nullptr, regexp_methods)) |
586 |
if (!DefinePropertiesAndFunctions(cx, proto, regexp_properties, regexp_methods)) |
| 521 |
return nullptr; |
587 |
return nullptr; |
| 522 |
|
588 |
|
| 523 |
RootedFunction ctor(cx); |
589 |
RootedFunction ctor(cx); |
| 524 |
ctor = global->createConstructor(cx, regexp_construct, cx->names().RegExp, 2); |
590 |
ctor = global->createConstructor(cx, regexp_construct, cx->names().RegExp, 2); |
| 525 |
if (!ctor) |
591 |
if (!ctor) |
| 526 |
return nullptr; |
592 |
return nullptr; |
| 527 |
|
593 |
|
| 528 |
if (!LinkConstructorAndPrototype(cx, ctor, proto)) |
594 |
if (!LinkConstructorAndPrototype(cx, ctor, proto)) |