1
0
Ver Fonte

Add JSObjectProxy >> {null,undefined}.

Herby Vojčík há 6 anos atrás
pai
commit
c1d084c1a8
5 ficheiros alterados com 146 adições e 33 exclusões
  1. 7 0
      API-CHANGES.txt
  2. 48 0
      src/Kernel-Infrastructure.js
  3. 10 0
      src/Kernel-Infrastructure.st
  4. 66 28
      src/Kernel-Tests.js
  5. 15 5
      src/Kernel-Tests.st

+ 7 - 0
API-CHANGES.txt

@@ -1,3 +1,10 @@
+0.21.1:
+
++ JSObjectProxy class >>
+  + null
+  + undefined
+
+
 0.21.0:
 
 * Deprecate SmalltalkImage >> existsJsGlobal:

+ 48 - 0
src/Kernel-Infrastructure.js

@@ -759,6 +759,30 @@ messageSends: []
 }),
 $globals.JSObjectProxy.a$cls);
 
+$core.addMethod(
+$core.method({
+selector: "null",
+protocol: "accessing",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return null;
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"null",{},$globals.JSObjectProxy.a$cls)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "null\x0a\x09<inlineJS: 'return null'>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.JSObjectProxy.a$cls);
+
 $core.addMethod(
 $core.method({
 selector: "on:",
@@ -785,6 +809,30 @@ messageSends: ["new", "jsObject:ofProxy:"]
 }),
 $globals.JSObjectProxy.a$cls);
 
+$core.addMethod(
+$core.method({
+selector: "undefined",
+protocol: "accessing",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return undefined;
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"undefined",{},$globals.JSObjectProxy.a$cls)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "undefined\x0a\x09<inlineJS: 'return undefined'>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.JSObjectProxy.a$cls);
+
 
 $core.addClass("Organizer", $globals.Object, ["elements"], "Kernel-Infrastructure");
 //>>excludeStart("ide", pragmas.excludeIdeData);

+ 10 - 0
src/Kernel-Infrastructure.st

@@ -183,6 +183,16 @@ putOn: aStream
 	aStream nextPutJSObject: jsObject
 ! !
 
+!JSObjectProxy class methodsFor: 'accessing'!
+
+null
+	<inlineJS: 'return null'>
+!
+
+undefined
+	<inlineJS: 'return undefined'>
+! !
+
 !JSObjectProxy class methodsFor: 'instance creation'!
 
 on: aJSObject

+ 66 - 28
src/Kernel-Tests.js

@@ -10417,30 +10417,6 @@ $globals.DateTest);
 
 
 $core.addClass("JSObjectProxyTest", $globals.TestCase, [], "Kernel-Tests");
-$core.addMethod(
-$core.method({
-selector: "jsNull",
-protocol: "accessing",
-fn: function (){
-var self=this,$self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-return null;
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"jsNull",{},$globals.JSObjectProxyTest)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "jsNull\x0a\x09<inlineJS: 'return null'>",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: []
-}),
-$globals.JSObjectProxyTest);
-
 $core.addMethod(
 $core.method({
 selector: "jsObject",
@@ -10982,6 +10958,37 @@ messageSends: ["assert:equals:", "c:", "jsObject"]
 }),
 $globals.JSObjectProxyTest);
 
+$core.addMethod(
+$core.method({
+selector: "testNull",
+protocol: "tests",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $2,$1;
+$2=$recv($globals.JSObjectProxy)._null();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["null"]=1;
+//>>excludeEnd("ctx");
+$1=$recv($2)._isNil();
+$self._assert_($1);
+$self._assert_equals_($recv($globals.JSON)._stringify_($globals.HashedCollection._newFromPairs_(["foo",$recv($globals.JSObjectProxy)._null()])),"{\x22foo\x22:null}");
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"testNull",{},$globals.JSObjectProxyTest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "testNull\x0a\x09self assert: JSObjectProxy null isNil.\x0a\x09self\x0a\x09\x09assert: (JSON stringify: #{#foo -> JSObjectProxy null})\x0a\x09\x09equals: '{\x22foo\x22:null}'",
+referencedClasses: ["JSObjectProxy", "JSON"],
+//>>excludeEnd("ide");
+messageSends: ["assert:", "isNil", "null", "assert:equals:", "stringify:"]
+}),
+$globals.JSObjectProxyTest);
+
 $core.addMethod(
 $core.method({
 selector: "testPrinting",
@@ -11100,7 +11107,7 @@ $self._assert_equals_($1,(1));
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["assert:equals:"]=1;
 //>>excludeEnd("ctx");
-$recv(jsObject)._a_($self._jsNull());
+$recv(jsObject)._a_($recv($globals.JSObjectProxy)._null());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["a:"]=1;
 //>>excludeEnd("ctx");
@@ -11157,10 +11164,41 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "testSetPropertyWithFalsyValue\x0a\x09| jsObject |\x0a\x09jsObject := self jsObject.\x0a\x09self assert: (jsObject a) equals: 1.\x0a\x0a\x09jsObject a: self jsNull.\x0a\x09self assert: (jsObject a) equals: nil.\x0a\x09jsObject a: 0.\x0a\x09self assert: (jsObject a) equals: 0.\x0a\x09jsObject a: self jsUndefined.\x0a\x09self assert: (jsObject a) equals: nil.\x0a\x09jsObject a: ''.\x0a\x09self assert: (jsObject a) equals: ''.\x0a\x09jsObject a: false.\x0a\x09self assert: (jsObject a) equals: false",
-referencedClasses: [],
+source: "testSetPropertyWithFalsyValue\x0a\x09| jsObject |\x0a\x09jsObject := self jsObject.\x0a\x09self assert: (jsObject a) equals: 1.\x0a\x0a\x09jsObject a: JSObjectProxy null.\x0a\x09self assert: (jsObject a) equals: nil.\x0a\x09jsObject a: 0.\x0a\x09self assert: (jsObject a) equals: 0.\x0a\x09jsObject a: self jsUndefined.\x0a\x09self assert: (jsObject a) equals: nil.\x0a\x09jsObject a: ''.\x0a\x09self assert: (jsObject a) equals: ''.\x0a\x09jsObject a: false.\x0a\x09self assert: (jsObject a) equals: false",
+referencedClasses: ["JSObjectProxy"],
+//>>excludeEnd("ide");
+messageSends: ["jsObject", "assert:equals:", "a", "a:", "null", "jsUndefined"]
+}),
+$globals.JSObjectProxyTest);
+
+$core.addMethod(
+$core.method({
+selector: "testUndefined",
+protocol: "tests",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $2,$1;
+$2=$recv($globals.JSObjectProxy)._undefined();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["undefined"]=1;
+//>>excludeEnd("ctx");
+$1=$recv($2)._isNil();
+$self._assert_($1);
+$self._assert_equals_($recv($globals.JSON)._stringify_($globals.HashedCollection._newFromPairs_(["foo",$recv($globals.JSObjectProxy)._undefined()])),"{}");
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"testUndefined",{},$globals.JSObjectProxyTest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "testUndefined\x0a\x09self assert: JSObjectProxy undefined isNil.\x0a\x09self\x0a\x09\x09assert: (JSON stringify: #{#foo -> JSObjectProxy undefined})\x0a\x09\x09equals: '{}'",
+referencedClasses: ["JSObjectProxy", "JSON"],
 //>>excludeEnd("ide");
-messageSends: ["jsObject", "assert:equals:", "a", "a:", "jsNull", "jsUndefined"]
+messageSends: ["assert:", "isNil", "undefined", "assert:equals:", "stringify:"]
 }),
 $globals.JSObjectProxyTest);
 

+ 15 - 5
src/Kernel-Tests.st

@@ -1908,10 +1908,6 @@ TestCase subclass: #JSObjectProxyTest
 
 !JSObjectProxyTest methodsFor: 'accessing'!
 
-jsNull
-	<inlineJS: 'return null'>
-!
-
 jsObject
 	<inlineJS: 
 		'return {a: 1, b: function() {return 2;}, c: function(object) {return object;}, d: "", "e": null, "f": void 0}'>
@@ -1990,6 +1986,13 @@ testMethodWithArguments
 	self assert: (self jsObject c: 1) equals: 1
 !
 
+testNull
+	self assert: JSObjectProxy null isNil.
+	self
+		assert: (JSON stringify: #{#foo -> JSObjectProxy null})
+		equals: '{"foo":null}'
+!
+
 testPrinting
 	self assert: self jsObject printString equals: '[object Object]'
 !
@@ -2017,7 +2020,7 @@ testSetPropertyWithFalsyValue
 	jsObject := self jsObject.
 	self assert: (jsObject a) equals: 1.
 
-	jsObject a: self jsNull.
+	jsObject a: JSObjectProxy null.
 	self assert: (jsObject a) equals: nil.
 	jsObject a: 0.
 	self assert: (jsObject a) equals: 0.
@@ -2029,6 +2032,13 @@ testSetPropertyWithFalsyValue
 	self assert: (jsObject a) equals: false
 !
 
+testUndefined
+	self assert: JSObjectProxy undefined isNil.
+	self
+		assert: (JSON stringify: #{#foo -> JSObjectProxy undefined})
+		equals: '{}'
+!
+
 testValue
 	| testObject |
 	testObject := self jsObject.