Ticket #2241: Patch_Spidermonkey_1.8.5_clone_wrappers_v0.1.diff

File Patch_Spidermonkey_1.8.5_clone_wrappers_v0.1.diff, 1.8 KB (added by Yves, 11 years ago)

A quick hack that fixes the cloning of objects containing wrappers.

  • js/src/jsclone.cpp

    Nur in js-1.8.5-edited/js/src: build-debug.
    Nur in js-1.8.5-edited/js/src: build-release.
    diff -u -r js-1.8.5/js/src/jsclone.cpp js-1.8.5-edited/js/src/jsclone.cpp
    old new  
    4040#include "jsdate.h"
    4141#include "jsregexp.h"
    4242#include "jstypedarray.h"
     43#include "jswrapper.h"
    4344
    4445#include "jsregexpinlines.h"
    4546
     
    503504bool
    504505JSStructuredCloneWriter::startWrite(const js::Value &v)
    505506{
     507    assertSameCompartment(context(), v);
     508
    506509    if (v.isString()) {
    507510        return writeString(SCTAG_STRING, v.toString());
    508511    } else if (v.isNumber()) {
     
    515518        return out.writePair(SCTAG_UNDEFINED, 0);
    516519    } else if (v.isObject()) {
    517520        JSObject *obj = &v.toObject();
     521
     522        // The object might be a security wrapper. See if we can clone what's
     523        // behind it. If we can, unwrap the object.
     524        obj = JS_UnwrapObject(context(), obj);
     525        if (!obj)
     526            return false;
     527
     528        // If we unwrapped above, we'll need to enter the underlying compartment.
     529        // Let the AutoEnterCompartment do the right thing for us.
     530        JSAutoEnterCompartment ac;
     531        if (!ac.enter(context(), obj))
     532            return false;
     533
    518534        if (obj->isRegExp()) {
    519535            RegExp *re = RegExp::extractFrom(obj);
    520536            return out.writePair(SCTAG_REGEXP_OBJECT, re->getFlags()) &&
     
    554570
    555571    while (!counts.empty()) {
    556572        JSObject *obj = &objs.back().toObject();
     573
     574        // The objects in |obj| can live in other compartments.
     575        JSAutoEnterCompartment ac;
     576        if (!ac.enter(context(), obj))
     577            return false;
     578
    557579        if (counts.back()) {
    558580            counts.back()--;
    559581            jsid id = ids.back();