Browse Source

BlockClosure: capture .prototype directly as ivar.

Herby Vojčík 5 years ago
parent
commit
aa15289601
2 changed files with 24 additions and 2 deletions
  1. 19 1
      lang/src/Kernel-Methods.js
  2. 5 1
      lang/src/Kernel-Methods.st

+ 19 - 1
lang/src/Kernel-Methods.js

@@ -4,7 +4,7 @@ var $pkg = $core.addPackage("Kernel-Methods");
 $pkg.innerEval = function (expr) { return eval(expr); };
 $pkg.transport = {"type":"amd","amdNamespace":"amber/core"};
 
-$core.addClass("BlockClosure", $globals.Object, [], "Kernel-Methods");
+$core.addClass("BlockClosure", $globals.Object, ["prototype"], "Kernel-Methods");
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.BlockClosure.comment="I represent a lexical closure.\x0aI am is directly mapped to JavaScript Function.\x0a\x0a## API\x0a\x0a1. Evaluation\x0a\x0a    My instances get evaluated with the `#value*` methods in the 'evaluating' protocol.\x0a\x0a    Example: ` [ :x | x + 1 ] value: 3 \x22Answers 4\x22 `\x0a\x0a2. Control structures\x0a\x0a    Blocks are used (together with `Boolean`) for control structures (methods in the `controlling` protocol).\x0a\x0a    Example: `aBlock whileTrue: [ ... ]`\x0a\x0a3. Error handling\x0a\x0a    I provide the `#on:do:` method for handling exceptions.\x0a\x0a    Example: ` aBlock on: MessageNotUnderstood do: [ :ex | ... ] `";
 //>>excludeEnd("ide");
@@ -342,6 +342,24 @@ messageSends: ["tryCatch:", "asSmalltalkException:", "ifTrue:ifFalse:", "isKindO
 }),
 $globals.BlockClosure);
 
+$core.addMethod(
+$core.method({
+selector: "prototype",
+protocol: "accessing",
+fn: function (){
+var self=this,$self=this;
+return $self.prototype;
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "prototype\x0a\x09^ prototype",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.BlockClosure);
+
 $core.addMethod(
 $core.method({
 selector: "provided",

+ 5 - 1
lang/src/Kernel-Methods.st

@@ -1,6 +1,6 @@
 Smalltalk createPackage: 'Kernel-Methods'!
 Object subclass: #BlockClosure
-	instanceVariableNames: ''
+	instanceVariableNames: 'prototype'
 	package: 'Kernel-Methods'!
 !BlockClosure commentStamp!
 I represent a lexical closure.
@@ -36,6 +36,10 @@ numArgs
 	<inlineJS: 'return self.length'>
 !
 
+prototype
+	^ prototype
+!
+
 receiver
 	^ nil
 ! !