diff --git a/js/src/jit-test/tests/basic/primitive-proto-properties.js b/js/src/jit-test/tests/basic/primitive-proto-properties.js new file mode 100644 index 000000000000..ea012e40e6d3 --- /dev/null +++ b/js/src/jit-test/tests/basic/primitive-proto-properties.js @@ -0,0 +1,47 @@ +function shadowing() { + Object.prototype.x = 1; + + for (var i = 0; i < 20; i++) { + var x = "a".x; + assertEq(x, i <= 15 ? 1 : "hello"); + + if (i == 15) { + String.prototype.x = "hello"; + } + } + + delete Object.prototype.x; +} + +function deleted() { + String.prototype.y = 1; + + for (var i = 0; i < 20; i++) { + var y = "a".y; + assertEq(y, i <= 15 ? 1 : undefined); + + if (i == 15) { + delete String.prototype.y; + } + } + + delete String.prototype.y; +} + + +function notdefined() { + for (var i = 0; i < 20; i++) { + var z = "a".z; + assertEq(z, i <= 15 ? undefined : "test"); + + if (i == 15) { + String.prototype.z = "test"; + } + } + + delete String.prototype.z; +} + +shadowing(); +deleted(); +notdefined(); diff --git a/js/src/jit/CacheIR.cpp b/js/src/jit/CacheIR.cpp index 8baf10a76428..cc39fa5a28e0 100644 --- a/js/src/jit/CacheIR.cpp +++ b/js/src/jit/CacheIR.cpp @@ -854,22 +854,26 @@ GetPropIRGenerator::tryAttachPrimitive(ValOperandId valId, HandleId id) if (!proto) return false; - // Instantiate this property, for use during Ion compilation. - if (IsIonEnabled(cx_)) - EnsureTrackPropertyTypes(cx_, proto, id); - - // For now, only look for properties directly set on the prototype. - Shape* shape = proto->lookup(cx_, id); - if (!shape || !shape->hasSlot() || !shape->hasDefaultGetter()) + RootedShape shape(cx_); + RootedNativeObject holder(cx_); + NativeGetPropCacheability type = CanAttachNativeGetProp(cx_, proto, id, &holder, &shape, pc_, + engine_, canAttachGetter_, + isTemporarilyUnoptimizable_); + if (type != CanAttachReadSlot) return false; + if (holder) { + // Instantiate this property, for use during Ion compilation. + if (IsIonEnabled(cx_)) + EnsureTrackPropertyTypes(cx_, holder, id); + } + writer.guardType(valId, primitiveType); maybeEmitIdGuard(id); ObjOperandId protoId = writer.loadObject(proto); - writer.guardShape(protoId, proto->lastProperty()); - EmitLoadSlotResult(writer, protoId, proto, shape); - writer.typeMonitorResult(); + EmitReadSlotResult(writer, proto, holder, shape, protoId); + EmitReadSlotReturn(writer, proto, holder, shape); return true; }