Bug 1323108 - Check own flags property in RegExpPrototypeOptimizableRaw. r=h4writer a=jcristau
authorTooru Fujisawa <arai_a@mac.com>
Sat, 17 Dec 2016 12:42:57 +0900
changeset 353115 eee45ae5b76bf308f6379e56880cd12d6a3cf74d
parent 353114 a87a36e49ccc487ea0d6c0d69c43a3b4cb4aeb81
child 353116 08b0f32008c2d4c9b386cf7316d3df7fc79ca22b
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersh4writer, jcristau
bugs1323108
milestone52.0a2
Bug 1323108 - Check own flags property in RegExpPrototypeOptimizableRaw. r=h4writer a=jcristau
js/src/builtin/RegExp.cpp
js/src/jsobj.cpp
js/src/jsobj.h
js/src/tests/ecma_6/RegExp/split-flags-on-obj.js
--- a/js/src/builtin/RegExp.cpp
+++ b/js/src/builtin/RegExp.cpp
@@ -1572,17 +1572,17 @@ js::RegExpPrototypeOptimizableRaw(JSCont
 
     Shape* shape = cx->compartment()->regExps.getOptimizableRegExpPrototypeShape();
     if (shape == nproto->lastProperty()) {
         *result = true;
         return true;
     }
 
     JSFunction* flagsGetter;
-    if (!GetGetterPure(cx, proto, NameToId(cx->names().flags), &flagsGetter))
+    if (!GetOwnGetterPure(cx, proto, NameToId(cx->names().flags), &flagsGetter))
         return false;
 
     if (!flagsGetter) {
         *result = false;
         return true;
     }
 
     if (!IsSelfHostedFunctionWithName(flagsGetter, cx->names().RegExpFlagsGetter)) {
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -2385,17 +2385,17 @@ js::GetPropertyPure(ExclusiveContext* cx
         vp->setUndefined();
         return true;
     }
 
     return pobj->isNative() && NativeGetPureInline(&pobj->as<NativeObject>(), shape, vp);
 }
 
 static inline bool
-NativeGetGetterPureInline(NativeObject* pobj, Shape* shape, JSFunction** fp)
+NativeGetGetterPureInline(Shape* shape, JSFunction** fp)
 {
     if (shape->hasGetterObject()) {
         if (shape->getterObject()->is<JSFunction>()) {
             *fp = &shape->getterObject()->as<JSFunction>();
             return true;
         }
     }
 
@@ -2413,18 +2413,33 @@ js::GetGetterPure(ExclusiveContext* cx, 
     if (!LookupPropertyPure(cx, obj, id, &pobj, &shape))
         return false;
 
     if (!shape) {
         *fp = nullptr;
         return true;
     }
 
-    return pobj->isNative() &&
-           NativeGetGetterPureInline(&pobj->as<NativeObject>(), shape, fp);
+    return pobj->isNative() && NativeGetGetterPureInline(shape, fp);
+}
+
+bool
+js::GetOwnGetterPure(ExclusiveContext* cx, JSObject* obj, jsid id, JSFunction** fp)
+{
+    JS::AutoCheckCannotGC nogc;
+    Shape* shape;
+    if (!LookupOwnPropertyPure(cx, obj, id, &shape))
+        return false;
+
+    if (!shape) {
+        *fp = nullptr;
+        return true;
+    }
+
+    return NativeGetGetterPureInline(shape, fp);
 }
 
 bool
 js::GetOwnNativeGetterPure(JSContext* cx, JSObject* obj, jsid id, JSNative* native)
 {
     JS::AutoCheckCannotGC nogc;
     *native = nullptr;
     Shape* shape;
--- a/js/src/jsobj.h
+++ b/js/src/jsobj.h
@@ -1259,16 +1259,19 @@ LookupOwnPropertyPure(ExclusiveContext* 
 
 bool
 GetPropertyPure(ExclusiveContext* cx, JSObject* obj, jsid id, Value* vp);
 
 bool
 GetGetterPure(ExclusiveContext* cx, JSObject* obj, jsid id, JSFunction** fp);
 
 bool
+GetOwnGetterPure(ExclusiveContext* cx, JSObject* obj, jsid id, JSFunction** fp);
+
+bool
 GetOwnNativeGetterPure(JSContext* cx, JSObject* obj, jsid id, JSNative* native);
 
 bool
 HasOwnDataPropertyPure(JSContext* cx, JSObject* obj, jsid id, bool* result);
 
 bool
 GetOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
                          MutableHandle<JS::PropertyDescriptor> desc);
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/RegExp/split-flags-on-obj.js
@@ -0,0 +1,21 @@
+var BUGNUMBER = 0;
+var summary = "RegExp.prototype.split should reflect the change to Object.prototype.flags.";
+
+print(BUGNUMBER + ": " + summary);
+
+Object.defineProperty(Object.prototype, "flags", Object.getOwnPropertyDescriptor(RegExp.prototype, "flags"));
+delete RegExp.prototype.flags;
+
+let re = /a/i;
+let a = re[Symbol.split]("1a2A3a4A5");
+assertDeepEq(a, ["1", "2", "3", "4", "5"]);
+
+delete Object.prototype.flags;
+
+Object.prototype.flags = "";
+
+a = re[Symbol.split]("1a2A3a4A5");
+assertDeepEq(a, ["1", "2A3", "4A5"]);
+
+if (typeof reportCompare === "function")
+    reportCompare(true, true);