Backout a4509a20f033 due to red, a=LegNeato THUNDERBIRD_8_0b3_BUILD1
authorChristian Legnitto <clegnitto@mozilla.com>
Tue, 18 Oct 2011 13:30:24 -0700
changeset 76341 f09e09f27623ea54f4096ae96374e5447803252c
parent 76340 75616c2e1ddf504eb74ef24c63c08f2ec820571a
child 76342 c2df065a768664598d34748df519d4cf45f435e5
child 76344 dd943de3de11b1b3e4f12f5c00ea20c4a551a222
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewersLegNeato
milestone8.0
backs outa4509a20f033697311c41e0072316ca02ee4feb4
Backout a4509a20f033 due to red, a=LegNeato
dom/plugins/base/nsJSNPRuntime.cpp
dom/plugins/test/mochitest/Makefile.in
dom/plugins/test/mochitest/test_defaultValue.html
js/src/jsapi.cpp
js/src/jsapi.h
--- a/dom/plugins/base/nsJSNPRuntime.cpp
+++ b/dom/plugins/base/nsJSNPRuntime.cpp
@@ -1679,49 +1679,25 @@ NPObjWrapper_NewResolve(JSContext *cx, J
     return fnc != nsnull;
   }
 
   // no property or method
   return JS_TRUE;
 }
 
 static JSBool
-NPObjWrapper_Convert(JSContext *cx, JSObject *obj, JSType hint, jsval *vp)
+NPObjWrapper_Convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
 {
-  JS_ASSERT(hint == JSTYPE_NUMBER || hint == JSTYPE_STRING || hint == JSTYPE_VOID);
-
-  // Plugins do not simply use JS_ConvertStub, and the default [[DefaultValue]]
-  // behavior, because that behavior involves calling toString or valueOf on
-  // objects which weren't designed to accommodate this.  Usually this wouldn't
-  // be a problem, because the absence of either property, or the presence of
-  // either property with a value that isn't callable, will cause that property
-  // to simply be ignored.  But there is a problem in one specific case: Java,
-  // specifically java.lang.Integer.  The Integer class has static valueOf
-  // methods, none of which are nullary, so the JS-reflected method will behave
-  // poorly when called with no arguments.  We work around this problem by
-  // giving plugins a [[DefaultValue]] which uses only toString and not valueOf.
-
-  jsval v = JSVAL_VOID;
-  if (!JS_GetProperty(cx, obj, "toString", &v))
-    return false;
-  if (!JSVAL_IS_PRIMITIVE(v) && JS_ObjectIsCallable(cx, JSVAL_TO_OBJECT(v))) {
-    if (!JS_CallFunctionValue(cx, obj, v, 0, NULL, vp))
-      return false;
-    if (JSVAL_IS_PRIMITIVE(*vp))
-      return true;
-  }
-
-  JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_CONVERT_TO,
-                       JS_GET_CLASS(cx, obj)->name,
-                       hint == JSTYPE_VOID
-                       ? "primitive type"
-                       : hint == JSTYPE_NUMBER
-                       ? "number"
-                       : "string");
-  return false;
+  // The sole reason we implement this hook is to prevent the JS
+  // engine from calling valueOf() on NPObject's. Some NPObject's may
+  // actually implement a method named valueOf, but it's unlikely to
+  // behave as the JS engine expects it to. IOW, this is an empty hook
+  // that overrides what the default hook does.
+
+  return JS_TRUE;
 }
 
 static void
 NPObjWrapper_Finalize(JSContext *cx, JSObject *obj)
 {
   NPObject *npobj = (NPObject *)::JS_GetPrivate(cx, obj);
   if (npobj) {
     if (sNPObjWrappers.ops) {
@@ -2211,21 +2187,16 @@ NPObjectMember_Convert(JSContext *cx, JS
     NS_ERROR("no Ambiguous Member Private data!");
     return JS_FALSE;
   }
 
   switch (type) {
   case JSTYPE_VOID:
   case JSTYPE_STRING:
   case JSTYPE_NUMBER:
-    *vp = memberPrivate->fieldValue;
-    if (!JSVAL_IS_PRIMITIVE(*vp)) {
-      return JS_DefaultValue(cx, JSVAL_TO_OBJECT(*vp), type, vp);
-    }
-    return JS_TRUE;
   case JSTYPE_BOOLEAN:
   case JSTYPE_OBJECT:
     *vp = memberPrivate->fieldValue;
     return JS_TRUE;
   case JSTYPE_FUNCTION:
     // Leave this to NPObjectMember_Call.
     return JS_TRUE;
   default:
--- a/dom/plugins/test/mochitest/Makefile.in
+++ b/dom/plugins/test/mochitest/Makefile.in
@@ -41,17 +41,16 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = dom/plugins/test
 
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _MOCHITEST_FILES = \
   utils.js \
-  test_defaultValue.html \
   test_getauthenticationinfo.html \
   test_npobject_getters.html \
   test_npruntime_npnevaluate.html \
   test_npruntime_npninvoke.html \
   test_npruntime_npninvokedefault.html \
   test_npruntime_identifiers.html \
   npruntime_identifiers_subpage.html \
   loremipsum.txt \
deleted file mode 100644
--- a/dom/plugins/test/mochitest/test_defaultValue.html
+++ /dev/null
@@ -1,36 +0,0 @@
-<html>
-  <head>
-    <title>NPObject [[DefaultValue]] implementation</title>
-
-    <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-  </head>
-
-  <body onload="run()">
-
-    <embed id="plugin" type="application/x-test" wmode="window"></embed>
-
-    <script class="testbody" type="application/javascript">
-      SimpleTest.waitForExplicitFinish();
-
-      function run() {
-        var plugin = document.getElementById("plugin");
-        var pluginProto = Object.getPrototypeOf(plugin);
-
-        plugin.propertyAndMethod = {};
-        plugin.propertyAndMethod + "baz";
-        ok(true, "|plugin.propertyAndMethod + \"baz\"| shouldn't assert");
-        pluginProto.propertyAndMethod = {};
-        pluginProto.propertyAndMethod + "quux";
-        ok(true, "|pluginProto.propertyAndMethod + \"quux\"| shouldn't assert");
-
-        plugin + "foo";
-        ok(true, "|plugin + \"foo\"| shouldn't assert");
-        pluginProto + "bar";
-        ok(true, "|pluginProto + \"bar\"| shouldn't assert");
-
-        SimpleTest.finish();
-      }
-    </script>
-  </body>
-</html>
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -2819,25 +2819,16 @@ JS_IdToValue(JSContext *cx, jsid id, jsv
 {
     CHECK_REQUEST(cx);
     *vp = IdToJsval(id);
     assertSameCompartment(cx, *vp);
     return JS_TRUE;
 }
 
 JS_PUBLIC_API(JSBool)
-JS_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp)
-{
-    CHECK_REQUEST(cx);
-    JS_ASSERT(obj != NULL);
-    JS_ASSERT(hint == JSTYPE_VOID || hint == JSTYPE_STRING || hint == JSTYPE_NUMBER);
-    return obj->defaultValue(cx, hint, vp);
-}
-
-JS_PUBLIC_API(JSBool)
 JS_PropertyStub(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
 {
     return JS_TRUE;
 }
 
 JS_PUBLIC_API(JSBool)
 JS_StrictPropertyStub(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
 {
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -2072,25 +2072,16 @@ JS_IdToValue(JSContext *cx, jsid id, jsv
  */
 #define JSRESOLVE_QUALIFIED     0x01    /* resolve a qualified property id */
 #define JSRESOLVE_ASSIGNING     0x02    /* resolve on the left of assignment */
 #define JSRESOLVE_DETECTING     0x04    /* 'if (o.p)...' or '(o.p) ?...:...' */
 #define JSRESOLVE_DECLARING     0x08    /* var, const, or function prolog op */
 #define JSRESOLVE_CLASSNAME     0x10    /* class name used when constructing */
 #define JSRESOLVE_WITH          0x20    /* resolve inside a with statement */
 
-/*
- * Invoke the [[DefaultValue]] hook (see ES5 8.6.2) with the provided hint on
- * the specified object, computing a primitive default value for the object.
- * The hint must be JSTYPE_STRING, JSTYPE_NUMBER, or JSTYPE_VOID (no hint).  On
- * success the resulting value is stored in *vp.
- */
-extern JS_PUBLIC_API(JSBool)
-JS_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp);
-
 extern JS_PUBLIC_API(JSBool)
 JS_PropertyStub(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
 
 extern JS_PUBLIC_API(JSBool)
 JS_StrictPropertyStub(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
 
 extern JS_PUBLIC_API(JSBool)
 JS_EnumerateStub(JSContext *cx, JSObject *obj);