Attachment #8728300: Display placeholder text for synthesized Debugger.Sources. for bug #1254893

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

(-)a/js/src/vm/Debugger.cpp (-8 / +37 lines)
Line     Link Here 
 Lines 6358-6391   DebuggerSource_checkThis(JSContext* cx, const CallArgs& args, const char* fnname Link Here 
6358
    CallArgs args = CallArgsFromVp(argc, vp);                                       \
6358
    CallArgs args = CallArgsFromVp(argc, vp);                                       \
6359
    RootedNativeObject obj(cx,                                                      \
6359
    RootedNativeObject obj(cx,                                                      \
6360
        DebuggerSource_checkThis<ScriptSourceObject*>(cx, args, fnname,             \
6360
        DebuggerSource_checkThis<ScriptSourceObject*>(cx, args, fnname,             \
6361
                                                      "a JS source"));              \
6361
                                                      "a JS source"));              \
6362
    if (!obj)                                                                       \
6362
    if (!obj)                                                                       \
6363
        return false;                                                               \
6363
        return false;                                                               \
6364
    RootedScriptSource sourceObject(cx, GetSourceReferent(obj).as<ScriptSourceObject*>())
6364
    RootedScriptSource sourceObject(cx, GetSourceReferent(obj).as<ScriptSourceObject*>())
6365
6365
6366
class DebuggerSourceGetTextMatcher
6367
{
6368
    JSContext* cx_;
6369
6370
  public:
6371
    explicit DebuggerSourceGetTextMatcher(JSContext* cx) : cx_(cx) { }
6372
6373
    using ReturnType = JSString*;
6374
6375
    ReturnType match(HandleScriptSource sourceObject) {
6376
        ScriptSource* ss = sourceObject->source();
6377
        bool hasSourceData = ss->hasSourceData();
6378
        if (!ss->hasSourceData() && !JSScript::loadSource(cx_, ss, &hasSourceData))
6379
            return nullptr;
6380
6381
        return hasSourceData ? ss->substring(cx_, 0, ss->length())
6382
                             : NewStringCopyZ<CanGC>(cx_, "[no source]");
6383
    }
6384
6385
    ReturnType match(Handle<WasmModuleObject*> wasmModule) {
6386
        const char* placeholder =
6387
            ".--.      .--.   ____       .-'''-. ,---.    ,---.\n"
6388
            "|  |_     |  | .'  __ `.   / _     \\|    \\  /    |\n"
6389
            "| _( )_   |  |/   '  \\  \\ (`' )/`--'|  ,  \\/  ,  |\n"
6390
            "|(_ o _)  |  ||___|  /  |(_ o _).   |  |\\_   /|  |\n"
6391
            "| (_,_) \\ |  |   _.-`   | (_,_). '. |  _( )_/ |  |\n"
6392
            "|  |/    \\|  |.'   _    |.---.  \\  :| (_ o _) |  |\n"
6393
            "|  '  /\\  `  ||  _( )_  |\\    `-'  ||  (_,_)  |  |\n"
6394
            "|    /  \\    |\\ (_ o _) / \\       / |  |      |  |\n"
6395
            "`---'    `---` '.(_,_).'   `-...-'  '--'      '--'\n";
6396
        return NewStringCopyZ<CanGC>(cx_, placeholder);
6397
    }
6398
};
6399
6366
static bool
6400
static bool
6367
DebuggerSource_getText(JSContext* cx, unsigned argc, Value* vp)
6401
DebuggerSource_getText(JSContext* cx, unsigned argc, Value* vp)
6368
{
6402
{
6369
    THIS_DEBUGSOURCE_SOURCE(cx, argc, vp, "(get text)", args, obj, sourceObject);
6403
    THIS_DEBUGSOURCE_REFERENT(cx, argc, vp, "(get text)", args, obj, referent);
6370
    Value textv = obj->getReservedSlot(JSSLOT_DEBUGSOURCE_TEXT);
6404
    Value textv = obj->getReservedSlot(JSSLOT_DEBUGSOURCE_TEXT);
6371
    if (!textv.isUndefined()) {
6405
    if (!textv.isUndefined()) {
6372
        MOZ_ASSERT(textv.isString());
6406
        MOZ_ASSERT(textv.isString());
6373
        args.rval().set(textv);
6407
        args.rval().set(textv);
6374
        return true;
6408
        return true;
6375
    }
6409
    }
6376
6410
6377
    ScriptSource* ss = sourceObject->source();
6411
    DebuggerSourceGetTextMatcher matcher(cx);
6378
    bool hasSourceData = ss->hasSourceData();
6412
    JSString* str = referent.match(matcher);
6379
    if (!ss->hasSourceData() && !JSScript::loadSource(cx, ss, &hasSourceData))
6380
        return false;
6381
6382
    JSString* str = hasSourceData ? ss->substring(cx, 0, ss->length())
6383
                                  : NewStringCopyZ<CanGC>(cx, "[no source]");
6384
    if (!str)
6413
    if (!str)
6385
        return false;
6414
        return false;
6386
6415
6387
    args.rval().setString(str);
6416
    args.rval().setString(str);
6388
    obj->setReservedSlot(JSSLOT_DEBUGSOURCE_TEXT, args.rval());
6417
    obj->setReservedSlot(JSSLOT_DEBUGSOURCE_TEXT, args.rval());
6389
    return true;
6418
    return true;
6390
}
6419
}

Return to bug 1254893