1
0
ソースを参照

Add #provided.

To allow `require provided resolve: 'package.json'`
instead of ugly `(JSObjectProxy on: require) resolve: ...`
or even worse ``(require basicAt: #resolve) value: ...`.

This happens only when JS function is used as
a namespace for API. Such occurrences are known,
so using dedicated selector can be justified (I hope).

It is by design only present in BlockClosure and Class
(to forward to constructor fn).
Herby Vojčík 6 年 前
コミット
4799544c56
5 ファイル変更73 行追加0 行削除
  1. 8 0
      API-CHANGES.txt
  2. 23 0
      src/Kernel-Classes.js
  3. 10 0
      src/Kernel-Classes.st
  4. 23 0
      src/Kernel-Methods.js
  5. 9 0
      src/Kernel-Methods.st

+ 8 - 0
API-CHANGES.txt

@@ -1,3 +1,11 @@
+0.22.1:
+
++ Class >>
+  + provided
++ Number >>
+  + provided
+
+
 0.22.0:
 
 * Deprecate Exception >> resignal. Should have been #pass.

+ 23 - 0
src/Kernel-Classes.js

@@ -839,6 +839,29 @@ messageSends: []
 }),
 $globals.Class);
 
+$core.addMethod(
+$core.method({
+selector: "provided",
+protocol: "converting",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($self._javascriptConstructor())._provided();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"provided",{},$globals.Class)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "provided\x0a\x09\x22Returns JS proxy that allows to access 'static API', as in\x0a\x09  Number provided EPSILON\x0a\x09that forwards to (wrapped JS) constructor function.\x22\x0a\x09\x0a\x09^ self javascriptConstructor provided",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["provided", "javascriptConstructor"]
+}),
+$globals.Class);
+
 $core.addMethod(
 $core.method({
 selector: "rename:",

+ 10 - 0
src/Kernel-Classes.st

@@ -199,6 +199,16 @@ theMetaClass
 	^ self class
 ! !
 
+!Class methodsFor: 'converting'!
+
+provided
+	"Returns JS proxy that allows to access 'static API', as in
+	  Number provided EPSILON
+	that forwards to (wrapped JS) constructor function."
+	
+	^ self javascriptConstructor provided
+! !
+
 !Class methodsFor: 'testing'!
 
 isClass

+ 23 - 0
src/Kernel-Methods.js

@@ -343,6 +343,29 @@ messageSends: ["tryCatch:", "asSmalltalkException:", "ifTrue:ifFalse:", "isKindO
 }),
 $globals.BlockClosure);
 
+$core.addMethod(
+$core.method({
+selector: "provided",
+protocol: "converting",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($globals.JSObjectProxy)._on_(self);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"provided",{},$globals.BlockClosure)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "provided\x0a\x09\x22Returns JS proxy that allows to access 'static API', as in\x0a\x09  require provided resolve: ...\x0a\x09or\x0a\x09  XMLHttpRequest provided DONE\x22\x0a\x09\x0a\x09^ JSObjectProxy on: self",
+referencedClasses: ["JSObjectProxy"],
+//>>excludeEnd("ide");
+messageSends: ["on:"]
+}),
+$globals.BlockClosure);
+
 $core.addMethod(
 $core.method({
 selector: "receiver",

+ 9 - 0
src/Kernel-Methods.st

@@ -77,6 +77,15 @@ currySelf
 			return self.apply(null, args);
 		}
 	'>
+!
+
+provided
+	"Returns JS proxy that allows to access 'static API', as in
+	  require provided resolve: ...
+	or
+	  XMLHttpRequest provided DONE"
+	
+	^ JSObjectProxy on: self
 ! !
 
 !BlockClosure methodsFor: 'error handling'!