1
0
Преглед на файлове

Smalltalk optOut: to treat certain objects as JS

To be used with wrapped objects (arrays, functions, dates).
`Smalltalk optOut: anObject` makes anObject a plain JS object
again (you can call its API etc.). It loses its Smalltalk nature
(no more value: and other Smalltalk API).

`Smalltalk cancelOptOut: anObject` gets back Smalltalk nature.
Herbert Vojčík преди 9 години
родител
ревизия
2de577fc36
променени са 3 файла, в които са добавени 69 реда и са изтрити 0 реда
  1. 3 0
      API-CHANGES.txt
  2. 48 0
      src/Kernel-Infrastructure.js
  3. 18 0
      src/Kernel-Infrastructure.st

+ 3 - 0
API-CHANGES.txt

@@ -26,6 +26,9 @@
   + methodOf:this:value:value:
   + methodOf:this:value:value:value:
   + methodOf:this:valueWithArgs:
++ SmalltalkImage >>
+  + optOut:
+  + cancelOptOut:
 
 
 0.14.0:

+ 48 - 0
src/Kernel-Infrastructure.js

@@ -4243,6 +4243,30 @@ messageSends: ["parse:"]
 }),
 $globals.SmalltalkImage);
 
+$core.addMethod(
+$core.method({
+selector: "cancelOptOut:",
+protocol: 'accessing',
+fn: function (anObject){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+delete anObject.klass;
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"cancelOptOut:",{anObject:anObject},$globals.SmalltalkImage)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anObject"],
+source: "cancelOptOut: anObject\x0a\x09\x22A Smalltalk object has a 'klass' property.\x0a\x09If this property is shadowed for anObject by optOut:,\x0a\x09the object is treated as plain JS object.\x0a\x09This removes the shadow and anObject is Smalltalk object\x0a\x09again if it was before.\x22\x0a\x09\x0a\x09<delete anObject.klass>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.SmalltalkImage);
+
 $core.addMethod(
 $core.method({
 selector: "classes",
@@ -4544,6 +4568,30 @@ messageSends: []
 }),
 $globals.SmalltalkImage);
 
+$core.addMethod(
+$core.method({
+selector: "optOut:",
+protocol: 'accessing',
+fn: function (anObject){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+anObject.klass = null;
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"optOut:",{anObject:anObject},$globals.SmalltalkImage)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anObject"],
+source: "optOut: anObject\x0a\x09\x22A Smalltalk object has a 'klass' property.\x0a\x09This shadows the property for anObject.\x0a\x09The object is treated as plain JS object following this.\x22\x0a\x09\x0a\x09<anObject.klass = null>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.SmalltalkImage);
+
 $core.addMethod(
 $core.method({
 selector: "packageAt:",

+ 18 - 0
src/Kernel-Infrastructure.st

@@ -1126,6 +1126,16 @@ It requires the `Compiler` package and the `support/parser.js` parser file in or
 
 !SmalltalkImage methodsFor: 'accessing'!
 
+cancelOptOut: anObject
+	"A Smalltalk object has a 'klass' property.
+	If this property is shadowed for anObject by optOut:,
+	the object is treated as plain JS object.
+	This removes the shadow and anObject is Smalltalk object
+	again if it was before."
+	
+	<delete anObject.klass>
+!
+
 core
 	<return $core>
 !
@@ -1138,6 +1148,14 @@ includesKey: aKey
 	<return $core.hasOwnProperty(aKey)>
 !
 
+optOut: anObject
+	"A Smalltalk object has a 'klass' property.
+	This shadows the property for anObject.
+	The object is treated as plain JS object following this."
+	
+	<anObject.klass = null>
+!
+
 parse: aString
 	| result |