Browse Source

ProtoObject >> == using JS ===.

Herbert Vojčík 7 years ago
parent
commit
1bd3f154e3
6 changed files with 48 additions and 96 deletions
  1. 14 0
      API-CHANGES.txt
  2. 27 31
      src/Kernel-Objects.js
  3. 6 6
      src/Kernel-Objects.st
  4. 0 49
      src/Kernel-Tests.js
  5. 0 10
      src/Kernel-Tests.st
  6. 1 0
      support/kernel-runtime.js

+ 14 - 0
API-CHANGES.txt

@@ -1,3 +1,17 @@
+0.19.1:
+
+* Deprecate amber/boot api nextId.
+* Deprecate ProtoObject >> identityHash.
+
++UndefinedObject >>
+  + ==
+
+- ProtoObject >>
+  - isSameInstanceAs:
+- ObjectTest >>
+  - testIdentityHash
+
+
 0.19.0:
 
 * Remove class Thenable, add trait TThenable.

+ 27 - 31
src/Kernel-Objects.js

@@ -43,7 +43,7 @@ var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return $self._class() === $recv(anObject)._class() && $self._isSameInstanceAs_(anObject);
+return self === anObject;
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"==",{anObject:anObject},$globals.ProtoObject)});
@@ -51,7 +51,7 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anObject"],
-source: "== anObject\x0a<inlineJS:\x0a\x09'return $self._class() === $recv(anObject)._class() && $self._isSameInstanceAs_(anObject)'>",
+source: "== anObject\x0a<inlineJS: 'return self === anObject'>",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
@@ -214,6 +214,7 @@ var self=this,$self=this;
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
 
+		self._deprecatedAPI();
 		var hash=self.identityHash;
 		if (hash) return hash;
 		hash=$core.nextId();
@@ -227,7 +228,7 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "identityHash\x0a\x09<inlineJS: '\x0a\x09\x09var hash=self.identityHash;\x0a\x09\x09if (hash) return hash;\x0a\x09\x09hash=$core.nextId();\x0a\x09\x09Object.defineProperty(self, ''identityHash'', {value:hash});\x0a\x09\x09return hash;\x0a\x09'>",
+source: "identityHash\x0a\x09<inlineJS: '\x0a\x09\x09self._deprecatedAPI();\x0a\x09\x09var hash=self.identityHash;\x0a\x09\x09if (hash) return hash;\x0a\x09\x09hash=$core.nextId();\x0a\x09\x09Object.defineProperty(self, ''identityHash'', {value:hash});\x0a\x09\x09return hash;\x0a\x09'>",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
@@ -476,34 +477,6 @@ messageSends: []
 }),
 $globals.ProtoObject);
 
-$core.addMethod(
-$core.method({
-selector: "isSameInstanceAs:",
-protocol: "comparing",
-fn: function (anObject){
-var self=this,$self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1;
-$1=$self._identityHash();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["identityHash"]=1;
-//>>excludeEnd("ctx");
-return $recv($1).__eq($recv(anObject)._identityHash());
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"isSameInstanceAs:",{anObject:anObject},$globals.ProtoObject)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["anObject"],
-source: "isSameInstanceAs: anObject\x0a\x09^ self identityHash = anObject identityHash",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["=", "identityHash"]
-}),
-$globals.ProtoObject);
-
 $core.addMethod(
 $core.method({
 selector: "notNil",
@@ -5553,6 +5526,29 @@ $core.addClass("UndefinedObject", $globals.Object, [], "Kernel-Objects");
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.UndefinedObject.comment="I describe the behavior of my sole instance, `nil`. `nil` represents a prior value for variables that have not been initialized, or for results which are meaningless.\x0a\x0a`nil` is the Smalltalk equivalent of the `undefined` JavaScript object.\x0a\x0a__note:__ When sending messages to the `undefined` JavaScript object, it will be replaced by `nil`.";
 //>>excludeEnd("ide");
+$core.addMethod(
+$core.method({
+selector: "==",
+protocol: "testing",
+fn: function (anObject){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv(anObject)._isNil();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"==",{anObject:anObject},$globals.UndefinedObject)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anObject"],
+source: "== anObject\x0a\x09^ anObject isNil",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["isNil"]
+}),
+$globals.UndefinedObject);
+
 $core.addMethod(
 $core.method({
 selector: "asJavaScriptObject",

+ 6 - 6
src/Kernel-Objects.st

@@ -15,6 +15,7 @@ class
 
 identityHash
 	<inlineJS: '
+		self._deprecatedAPI();
 		var hash=self.identityHash;
 		if (hash) return hash;
 		hash=$core.nextId();
@@ -42,12 +43,7 @@ yourself
 !
 
 == anObject
-<inlineJS:
-	'return $self._class() === $recv(anObject)._class() && $self._isSameInstanceAs_(anObject)'>
-!
-
-isSameInstanceAs: anObject
-	^ self identityHash = anObject identityHash
+<inlineJS: 'return self === anObject'>
 !
 
 ~= anObject
@@ -1346,6 +1342,10 @@ printOn: aStream
 
 !UndefinedObject methodsFor: 'testing'!
 
+== anObject
+	^ anObject isNil
+!
+
 ifNil: aBlock
 	"inlined in the Compiler"
 	^ self ifNil: aBlock ifNotNil: []

+ 0 - 49
src/Kernel-Tests.js

@@ -14111,55 +14111,6 @@ messageSends: ["new", "assert:", "==", "yourself"]
 }),
 $globals.ObjectTest);
 
-$core.addMethod(
-$core.method({
-selector: "testidentityHash",
-protocol: "tests",
-fn: function (){
-var self=this,$self=this;
-var o1,o2;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $2,$3,$1,$5,$4;
-o1=$recv($globals.Object)._new();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["new"]=1;
-//>>excludeEnd("ctx");
-o2=$recv($globals.Object)._new();
-$2=$recv(o1)._identityHash();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["identityHash"]=1;
-//>>excludeEnd("ctx");
-$3=$recv(o1)._identityHash();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["identityHash"]=2;
-//>>excludeEnd("ctx");
-$1=$recv($2).__eq_eq($3);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["=="]=1;
-//>>excludeEnd("ctx");
-$self._assert_($1);
-$5=$recv(o1)._identityHash();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["identityHash"]=3;
-//>>excludeEnd("ctx");
-$4=$recv($5).__eq_eq($recv(o2)._identityHash());
-$self._deny_($4);
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"testidentityHash",{o1:o1,o2:o2},$globals.ObjectTest)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "testidentityHash\x0a\x09| o1 o2 |\x0a\x09\x0a\x09o1 := Object new.\x0a\x09o2 := Object new.\x0a\x0a\x09self assert: o1 identityHash == o1 identityHash.\x0a\x09self deny: o1 identityHash == o2 identityHash",
-referencedClasses: ["Object"],
-//>>excludeEnd("ide");
-messageSends: ["new", "assert:", "==", "identityHash", "deny:"]
-}),
-$globals.ObjectTest);
-
 
 
 $core.addClass("PointTest", $globals.TestCase, [], "Kernel-Tests");

+ 0 - 10
src/Kernel-Tests.st

@@ -2558,16 +2558,6 @@ testYourself
 	| o |
 	o := ObjectMock new.
 	self assert: o yourself == o
-!
-
-testidentityHash
-	| o1 o2 |
-	
-	o1 := Object new.
-	o2 := Object new.
-
-	self assert: o1 identityHash == o1 identityHash.
-	self deny: o1 identityHash == o2 identityHash
 ! !
 
 TestCase subclass: #PointTest

+ 1 - 0
support/kernel-runtime.js

@@ -199,6 +199,7 @@ define(function () {
         var oid = 0;
         /* Unique ID number generator */
         st.nextId = function () {
+            console.warn("$core.nextId() deprecated. Use your own unique counter.");
             oid += 1;
             return oid;
         };