| 1 | --- js-1.8.5/js/src/jsclone.cpp |
| 2 | +++ js-1.8.5/js/src/jsclone.cpp |
| 3 | @@ -40,6 +40,7 @@ |
| 4 | #include "jsdate.h" |
| 5 | #include "jsregexp.h" |
| 6 | #include "jstypedarray.h" |
| 7 | +#include "jswrapper.h" |
| 8 | |
| 9 | #include "jsregexpinlines.h" |
| 10 | |
| 11 | @@ -503,6 +504,8 @@ |
| 12 | bool |
| 13 | JSStructuredCloneWriter::startWrite(const js::Value &v) |
| 14 | { |
| 15 | + assertSameCompartment(context(), v); |
| 16 | + |
| 17 | if (v.isString()) { |
| 18 | return writeString(SCTAG_STRING, v.toString()); |
| 19 | } else if (v.isNumber()) { |
| 20 | @@ -515,6 +518,19 @@ |
| 21 | return out.writePair(SCTAG_UNDEFINED, 0); |
| 22 | } else if (v.isObject()) { |
| 23 | JSObject *obj = &v.toObject(); |
| 24 | + |
| 25 | + // The object might be a security wrapper. See if we can clone what's |
| 26 | + // behind it. If we can, unwrap the object. |
| 27 | + obj = JS_UnwrapObject(context(), obj); |
| 28 | + if (!obj) |
| 29 | + return false; |
| 30 | + |
| 31 | + // If we unwrapped above, we'll need to enter the underlying compartment. |
| 32 | + // Let the AutoEnterCompartment do the right thing for us. |
| 33 | + JSAutoEnterCompartment ac; |
| 34 | + if (!ac.enter(context(), obj)) |
| 35 | + return false; |
| 36 | + |
| 37 | if (obj->isRegExp()) { |
| 38 | RegExp *re = RegExp::extractFrom(obj); |
| 39 | return out.writePair(SCTAG_REGEXP_OBJECT, re->getFlags()) && |
| 40 | @@ -554,6 +570,12 @@ |
| 41 | |
| 42 | while (!counts.empty()) { |
| 43 | JSObject *obj = &objs.back().toObject(); |
| 44 | + |
| 45 | + // The objects in |obj| can live in other compartments. |
| 46 | + JSAutoEnterCompartment ac; |
| 47 | + if (!ac.enter(context(), obj)) |
| 48 | + return false; |
| 49 | + |
| 50 | if (counts.back()) { |
| 51 | counts.back()--; |
| 52 | jsid id = ids.back(); |