diff --git a/mozilla/js2/src/js2engine.cpp b/mozilla/js2/src/js2engine.cpp index b02306d3a2a..efc5f919598 100644 --- a/mozilla/js2/src/js2engine.cpp +++ b/mozilla/js2/src/js2engine.cpp @@ -805,12 +805,11 @@ namespace MetaData { } // XXX Default construction of an instance of the class - // that is the value at the top of the execution stack - js2val JS2Engine::defaultConstructor(JS2Metadata *meta, const js2val /* thisValue */, js2val /* argv */ [], uint32 /* argc */) + // that is the value of the passed in 'this' + js2val JS2Engine::defaultConstructor(JS2Metadata *meta, const js2val thisValue, js2val /* argv */ [], uint32 /* argc */) { - js2val v = meta->engine->top(); - ASSERT(JS2VAL_IS_OBJECT(v) && !JS2VAL_IS_NULL(v)); - JS2Object *obj = JS2VAL_TO_OBJECT(v); + ASSERT(JS2VAL_IS_OBJECT(thisValue) && !JS2VAL_IS_NULL(thisValue)); + JS2Object *obj = JS2VAL_TO_OBJECT(thisValue); ASSERT(obj->kind == ClassKind); JS2Class *c = checked_cast(obj); if (c->prototype) diff --git a/mozilla/js2/src/js2eval.cpp b/mozilla/js2/src/js2eval.cpp index 60f45baac84..6b01520d5d3 100644 --- a/mozilla/js2/src/js2eval.cpp +++ b/mozilla/js2/src/js2eval.cpp @@ -459,8 +459,23 @@ namespace MetaData { return (JS2VAL_TO_BOOLEAN(x)) ? 1.0 : 0.0; if (JS2VAL_IS_STRING(x)) { String *str = JS2VAL_TO_STRING(x); + uint32 length = str->length(); + if (length == 0) + return 0.0; const char16 *numEnd; - return stringToDouble(str->data(), str->data() + str->length(), numEnd); + // if the string begins with '0X' or '0x' (after white space), then + // read it as a hex integer. + const char16 *strStart = str->data(); + const char16 *strEnd = strStart + length; + const char16 *str1 = skipWhiteSpace(strStart, strEnd); + if ((*str1 == '0') && ((str1[1] == 'x') || (str1[1] == 'X'))) + return stringToInteger(str1, strEnd, numEnd, 16); + else { + float64 d = stringToDouble(str1, strEnd, numEnd); + if (numEnd == str1) + return nan; + return d; + } } if (JS2VAL_IS_INACCESSIBLE(x)) reportError(Exception::compileExpressionError, "Inappropriate compile time expression", engine->errorPos()); diff --git a/mozilla/js2/src/js2op_invocation.cpp b/mozilla/js2/src/js2op_invocation.cpp index 2f5eacd610a..9890099acd9 100644 --- a/mozilla/js2/src/js2op_invocation.cpp +++ b/mozilla/js2/src/js2op_invocation.cpp @@ -38,11 +38,13 @@ uint16 argCount = BytecodeContainer::getShort(pc); pc += sizeof(uint16); a = top(argCount + 1); - ASSERT(JS2VAL_IS_OBJECT(a) && !JS2VAL_IS_NULL(a)); + if (!JS2VAL_IS_OBJECT(a) || JS2VAL_IS_NULL(a)) { + meta->reportError(Exception::badValueError, "object is not a constructor", errorPos()); + } JS2Object *obj = JS2VAL_TO_OBJECT(a); if (obj->kind == ClassKind) { JS2Class *c = checked_cast(obj); - a = c->construct(meta, JS2VAL_NULL, base(argCount), argCount); + a = c->construct(meta, a, base(argCount), argCount); pop(argCount + 1); push(a); }