Attachment #8533470: feedback addressed for bug #1108467

View | Details | Raw Unified | Return to bug 1108467
Collapse All | Expand All

(-)a/js/src/builtin/RegExp.cpp (-1 / +67 lines)
Line     Link Here 
 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))
(-)a/js/src/builtin/RegExp.h (+3 lines)
Line     Link Here 
 Lines 7-22    Link Here 
7
#ifndef builtin_RegExp_h
7
#ifndef builtin_RegExp_h
8
#define builtin_RegExp_h
8
#define builtin_RegExp_h
9
9
10
#include "vm/RegExpObject.h"
10
#include "vm/RegExpObject.h"
11
11
12
JSObject *
12
JSObject *
13
js_InitRegExpClass(JSContext *cx, js::HandleObject obj);
13
js_InitRegExpClass(JSContext *cx, js::HandleObject obj);
14
14
15
bool
16
regexp_flags(JSContext *cx, unsigned argc, JS::Value *vp);
17
15
/*
18
/*
16
 * The following builtin natives are extern'd for pointer comparison in
19
 * The following builtin natives are extern'd for pointer comparison in
17
 * other parts of the engine.
20
 * other parts of the engine.
18
 */
21
 */
19
22
20
namespace js {
23
namespace js {
21
24
22
// Whether RegExp statics should be updated with the input and results of a
25
// Whether RegExp statics should be updated with the input and results of a
(-)a/js/src/tests/ecma_6/RegExp/flags.js (+28 lines)
Line     Link Here 
Line 0    Link Here 
1
var BUGNUMBER = 1108467;
2
var summary = "Implement RegExp.prototype.flags";
3
4
print(BUGNUMBER + ": " + summary);
5
6
assertEq(RegExp.prototype.flags, "");
7
assertEq(/foo/iymg.flags, "gimy");
8
assertEq(RegExp("").flags, "");
9
assertEq(RegExp("", "mygi").flags, "gimy");
10
assertThrowsInstanceOf(() => RegExp("", "mygui").flags, SyntaxError);
11
// When the /u flag is supported, uncomment the line below and remove the line above
12
// assertEq(RegExp("", "mygui").flags, "gimyu");
13
assertEq(genericFlags({}), "");
14
assertEq(genericFlags({ignoreCase: true}), "i");
15
assertEq(genericFlags({sticky:1, unicode:1, global: 0}), "yu");
16
assertEq(genericFlags({__proto__: {multiline: true}}), "m");
17
assertEq(genericFlags(new Proxy({}, {get(){return true}})), "gimyu");
18
19
assertThrowsInstanceOf(() => genericFlags(), TypeError);
20
assertThrowsInstanceOf(() => genericFlags(1), TypeError);
21
assertThrowsInstanceOf(() => genericFlags(""), TypeError);
22
23
function genericFlags(obj) {
24
    return Object.getOwnPropertyDescriptor(RegExp.prototype,"flags").get.call(obj);
25
}
26
27
if (typeof reportCompare === "function")
28
    reportCompare(true, true);
(-)a/js/src/vm/CommonPropertyNames.h (+1 lines)
Line     Link Here 
 Lines 191-206    Link Here 
191
    macro(toJSON, toJSON, "toJSON") \
191
    macro(toJSON, toJSON, "toJSON") \
192
    macro(toLocaleString, toLocaleString, "toLocaleString") \
192
    macro(toLocaleString, toLocaleString, "toLocaleString") \
193
    macro(toSource, toSource, "toSource") \
193
    macro(toSource, toSource, "toSource") \
194
    macro(toString, toString, "toString") \
194
    macro(toString, toString, "toString") \
195
    macro(toUTCString, toUTCString, "toUTCString") \
195
    macro(toUTCString, toUTCString, "toUTCString") \
196
    macro(true, true_, "true") \
196
    macro(true, true_, "true") \
197
    macro(unescape, unescape, "unescape") \
197
    macro(unescape, unescape, "unescape") \
198
    macro(uneval, uneval, "uneval") \
198
    macro(uneval, uneval, "uneval") \
199
    macro(unicode, unicode, "unicode") \
199
    macro(uninitialized, uninitialized, "uninitialized") \
200
    macro(uninitialized, uninitialized, "uninitialized") \
200
    macro(uint8, uint8, "uint8") \
201
    macro(uint8, uint8, "uint8") \
201
    macro(uint8Clamped, uint8Clamped, "uint8Clamped") \
202
    macro(uint8Clamped, uint8Clamped, "uint8Clamped") \
202
    macro(uint16, uint16, "uint16") \
203
    macro(uint16, uint16, "uint16") \
203
    macro(uint32, uint32, "uint32") \
204
    macro(uint32, uint32, "uint32") \
204
    macro(unsized, unsized, "unsized") \
205
    macro(unsized, unsized, "unsized") \
205
    macro(unwatch, unwatch, "unwatch") \
206
    macro(unwatch, unwatch, "unwatch") \
206
    macro(url, url, "url") \
207
    macro(url, url, "url") \

Return to bug 1108467