Skip to content

Commit

Permalink
Rename thisObjectLibrary to instanceObjectLibrary.
Browse files Browse the repository at this point in the history
  • Loading branch information
skinny85 committed May 4, 2024
1 parent a9e8a15 commit 61e1e9b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ boolean hasMembers() {

@ExportMessage
boolean isMemberReadable(String member,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary,
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary,
@CachedLibrary("this.classPrototypeObject") DynamicObjectLibrary prototypeObjectLibrary) {
return thisObjectLibrary.containsKey(this, member) ||
return instanceObjectLibrary.containsKey(this, member) ||
prototypeObjectLibrary.containsKey(this.classPrototypeObject, member);
}

@ExportMessage
Object readMember(String member,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary,
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary,
@CachedLibrary("this.classPrototypeObject") DynamicObjectLibrary prototypeObjectLibrary)
throws UnknownIdentifierException {
// since ClassInstanceObject is mutable, we need to check it first, before the prototype
Object value = thisObjectLibrary.getOrDefault(this, member, null);
Object value = instanceObjectLibrary.getOrDefault(this, member, null);
if (value == null) {
value = prototypeObjectLibrary.getOrDefault(this.classPrototypeObject, member, null);
}
Expand All @@ -76,21 +76,21 @@ Object getMembers(@SuppressWarnings("unused") boolean includeInternal,

@ExportMessage
boolean isMemberModifiable(String member,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary,
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary,
@CachedLibrary("this.classPrototypeObject") DynamicObjectLibrary prototypeObjectLibrary) {
return this.isMemberReadable(member, thisObjectLibrary, prototypeObjectLibrary);
return this.isMemberReadable(member, instanceObjectLibrary, prototypeObjectLibrary);
}

@ExportMessage
boolean isMemberInsertable(String member,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary,
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary,
@CachedLibrary("this.classPrototypeObject") DynamicObjectLibrary prototypeObjectLibrary) {
return !this.isMemberModifiable(member, thisObjectLibrary, prototypeObjectLibrary);
return !this.isMemberModifiable(member, instanceObjectLibrary, prototypeObjectLibrary);
}

@ExportMessage
void writeMember(String member, Object value,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary) {
thisObjectLibrary.put(this, member, value);
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary) {
instanceObjectLibrary.put(this, member, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private DynamicObject createGlobalScopeObject(DynamicObjectLibrary objectLibrary
this.createMathObject(objectLibrary), 0);

// initialize the Object prototype
objectLibrary.putConstant( this.objectPrototype, "hasOwnProperty",
objectLibrary.putConstant(this.objectPrototype, "hasOwnProperty",
this.defineBuiltInMethod(HasOwnPropertyMethodBodyExprNodeFactory.getInstance()),
0);
objectLibrary.putConstant(globalScopeObject, "Object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.endoflineblog.truffle.part_13.exceptions.EasyScriptException;
import com.endoflineblog.truffle.part_13.nodes.EasyScriptNode;
import com.endoflineblog.truffle.part_13.nodes.exprs.strings.ReadTruffleStringPropertyNode;
import com.endoflineblog.truffle.part_13.runtime.ClassPrototypeObject;
import com.endoflineblog.truffle.part_13.runtime.EasyScriptTruffleStrings;
import com.endoflineblog.truffle.part_13.runtime.ObjectPrototype;
import com.endoflineblog.truffle.part_13.runtime.Undefined;
Expand All @@ -14,7 +13,6 @@
import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObjectLibrary;
import com.oracle.truffle.api.strings.TruffleString;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ protected Object readNonLengthProperty(
@Cached("currentLanguageContext().shapesAndPrototypes.stringPrototype") ClassPrototypeObject stringPrototype,
@CachedLibrary(limit = "2") InteropLibrary interopLibrary) {
try {
return interopLibrary.readMember(stringPrototype, property.toString());
return interopLibrary.readMember(stringPrototype,
EasyScriptTruffleStrings.toString(property));
} catch (UnknownIdentifierException e) {
return Undefined.INSTANCE;
} catch (UnsupportedMessageException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public ClassPrototypeObject(Shape shape, String className,

@ExportMessage
Object readMember(String member,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary,
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary,
@CachedLibrary("this.superClassPrototype") InteropLibrary superClassInteropLibrary)
throws UnknownIdentifierException, UnsupportedMessageException {
Object value = thisObjectLibrary.getOrDefault(this, member, null);
Object value = instanceObjectLibrary.getOrDefault(this, member, null);
if (value == null) {
return superClassInteropLibrary.readMember(this.superClassPrototype, member);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ boolean hasMembers() {

@ExportMessage
boolean isMemberReadable(String member,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary) {
return thisObjectLibrary.containsKey(this, member);
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary) {
return instanceObjectLibrary.containsKey(this, member);
}

@ExportMessage
Object readMember(String member,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary)
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary)
throws UnknownIdentifierException {
Object value = thisObjectLibrary.getOrDefault(this, member, null);
Object value = instanceObjectLibrary.getOrDefault(this, member, null);
if (value == null) {
throw UnknownIdentifierException.create(member);
}
Expand All @@ -39,25 +39,25 @@ Object readMember(String member,

@ExportMessage
Object getMembers(@SuppressWarnings("unused") boolean includeInternal,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary) {
return new MemberNamesObject(thisObjectLibrary.getKeyArray(this));
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary) {
return new MemberNamesObject(instanceObjectLibrary.getKeyArray(this));
}

@ExportMessage
boolean isMemberModifiable(String member,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary) {
return this.isMemberReadable(member, thisObjectLibrary);
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary) {
return this.isMemberReadable(member, instanceObjectLibrary);
}

@ExportMessage
boolean isMemberInsertable(String member,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary) {
return !this.isMemberModifiable(member, thisObjectLibrary);
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary) {
return !this.isMemberModifiable(member, instanceObjectLibrary);
}

@ExportMessage
void writeMember(String member, Object value,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary) {
thisObjectLibrary.put(this, member, value);
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary) {
instanceObjectLibrary.put(this, member, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ Object toDisplayString(@SuppressWarnings("unused") boolean allowSideEffects) {

@ExportMessage
boolean isMemberReadable(String member,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary,
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary,
@CachedLibrary("this.classPrototypeObject") DynamicObjectLibrary prototypeObjectLibrary) {
return thisObjectLibrary.containsKey(this, member) ||
return instanceObjectLibrary.containsKey(this, member) ||
prototypeObjectLibrary.containsKey(this.classPrototypeObject, member);
}

@ExportMessage
Object readMember(String member,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary,
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary,
@CachedLibrary("this.classPrototypeObject") InteropLibrary prototypeInteropLibrary)
throws UnknownIdentifierException, UnsupportedMessageException {
// since ClassInstanceObject is mutable, we need to check it first, before the prototype
Object value = thisObjectLibrary.getOrDefault(this, member, null);
Object value = instanceObjectLibrary.getOrDefault(this, member, null);
if (value == null) {
return prototypeInteropLibrary.readMember(this.classPrototypeObject, member);
}
Expand All @@ -62,15 +62,15 @@ Object readMember(String member,

@ExportMessage
boolean isMemberModifiable(String member,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary,
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary,
@CachedLibrary("this.classPrototypeObject") DynamicObjectLibrary prototypeObjectLibrary) {
return this.isMemberReadable(member, thisObjectLibrary, prototypeObjectLibrary);
return this.isMemberReadable(member, instanceObjectLibrary, prototypeObjectLibrary);
}

@ExportMessage
boolean isMemberInsertable(String member,
@CachedLibrary("this") DynamicObjectLibrary thisObjectLibrary,
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary,
@CachedLibrary("this.classPrototypeObject") DynamicObjectLibrary prototypeObjectLibrary) {
return !this.isMemberModifiable(member, thisObjectLibrary, prototypeObjectLibrary);
return !this.isMemberModifiable(member, instanceObjectLibrary, prototypeObjectLibrary);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@ExportLibrary(InteropLibrary.class)
public final class ObjectPrototype extends AbstractClassPrototypeObject {
public ObjectPrototype(Shape rootShape) {
super(rootShape, "Object");
public ObjectPrototype(Shape shape) {
super(shape, "Object");
}
}

0 comments on commit 61e1e9b

Please sign in to comment.