resin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/README.markdown +52 -0
  2. data/amber/css/amber.css +519 -0
  3. data/amber/css/documentation.css +84 -0
  4. data/amber/css/profstef.css +75 -0
  5. data/amber/css/style.css +313 -0
  6. data/amber/images/amber.png +0 -0
  7. data/amber/images/amber_small.png +0 -0
  8. data/amber/images/off.png +0 -0
  9. data/amber/images/offHover.png +0 -0
  10. data/amber/images/presentation.png +0 -0
  11. data/amber/images/profstef.png +0 -0
  12. data/amber/images/sprite.png +0 -0
  13. data/amber/images/tinylogo.png +0 -0
  14. data/amber/images/twitterwall.png +0 -0
  15. data/amber/js/Additional-Examples.deploy.js +15 -0
  16. data/amber/js/Additional-Examples.js +21 -0
  17. data/amber/js/Benchfib.deploy.js +132 -0
  18. data/amber/js/Benchfib.js +167 -0
  19. data/amber/js/Canvas.deploy.js +1304 -0
  20. data/amber/js/Canvas.js +1885 -0
  21. data/amber/js/Compiler.deploy.js +1871 -0
  22. data/amber/js/Compiler.js +2616 -0
  23. data/amber/js/Documentation.deploy.js +961 -0
  24. data/amber/js/Documentation.js +1376 -0
  25. data/amber/js/Examples.deploy.js +53 -0
  26. data/amber/js/Examples.js +73 -0
  27. data/amber/js/IDE.deploy.js +3468 -0
  28. data/amber/js/IDE.js +4883 -0
  29. data/amber/js/Kernel-Announcements.deploy.js +107 -0
  30. data/amber/js/Kernel-Announcements.js +152 -0
  31. data/amber/js/Kernel-Classes.deploy.js +675 -0
  32. data/amber/js/Kernel-Classes.js +956 -0
  33. data/amber/js/Kernel-Collections.deploy.js +3273 -0
  34. data/amber/js/Kernel-Collections.js +4644 -0
  35. data/amber/js/Kernel-Exceptions.deploy.js +244 -0
  36. data/amber/js/Kernel-Exceptions.js +349 -0
  37. data/amber/js/Kernel-Methods.deploy.js +510 -0
  38. data/amber/js/Kernel-Methods.js +739 -0
  39. data/amber/js/Kernel-Objects.deploy.js +2698 -0
  40. data/amber/js/Kernel-Objects.js +3858 -0
  41. data/amber/js/Kernel-Tests.deploy.js +1419 -0
  42. data/amber/js/Kernel-Tests.js +1929 -0
  43. data/amber/js/Kernel-Transcript.deploy.js +142 -0
  44. data/amber/js/Kernel-Transcript.js +202 -0
  45. data/amber/js/SUnit.deploy.js +351 -0
  46. data/amber/js/SUnit.js +501 -0
  47. data/amber/js/amber.js +250 -0
  48. data/amber/js/boot.js +587 -0
  49. data/amber/js/compat.js +22 -0
  50. data/amber/js/init.js +8 -0
  51. data/amber/js/lib/CodeMirror/LICENSE +19 -0
  52. data/amber/js/lib/CodeMirror/amber.css +21 -0
  53. data/amber/js/lib/CodeMirror/codemirror.css +67 -0
  54. data/amber/js/lib/CodeMirror/codemirror.js +2144 -0
  55. data/amber/js/lib/CodeMirror/smalltalk.js +134 -0
  56. data/amber/js/lib/jQuery/jquery-1.4.4.min.js +167 -0
  57. data/amber/js/lib/jQuery/jquery-1.6.4.min.js +4 -0
  58. data/amber/js/lib/jQuery/jquery-ui-1.8.16.custom.min.js +791 -0
  59. data/amber/js/lib/jQuery/jquery.textarea.js +267 -0
  60. data/amber/js/lib/peg-0.6.2.min.js +2 -0
  61. data/amber/js/lib/showdown.js +419 -0
  62. data/amber/js/parser.js +4005 -0
  63. data/amber/js/parser.pegjs +220 -0
  64. data/amber/st/Benchfib.st +124 -0
  65. data/amber/st/Canvas.st +556 -0
  66. data/amber/st/Compiler.st +1425 -0
  67. data/amber/st/Documentation.st +758 -0
  68. data/amber/st/Examples.st +38 -0
  69. data/amber/st/IDE.st +2336 -0
  70. data/amber/st/Kernel-Announcements.st +61 -0
  71. data/amber/st/Kernel-Classes.st +403 -0
  72. data/amber/st/Kernel-Collections.st +1673 -0
  73. data/amber/st/Kernel-Exceptions.st +124 -0
  74. data/amber/st/Kernel-Methods.st +287 -0
  75. data/amber/st/Kernel-Objects.st +1489 -0
  76. data/amber/st/Kernel-Tests.st +892 -0
  77. data/amber/st/Kernel-Transcript.st +70 -0
  78. data/amber/st/SUnit.st +172 -0
  79. data/bin/runresin +12 -0
  80. data/lib/resin.rb +0 -0
  81. data/lib/resin/app/app.rb +121 -0
  82. data/lib/resin/app/views/index.haml +10 -0
  83. metadata +216 -0
@@ -0,0 +1,124 @@
1
+ Smalltalk current createPackage: 'Kernel-Exceptions' properties: #{}!
2
+ Object subclass: #Error
3
+ instanceVariableNames: 'messageText'
4
+ category: 'Kernel-Exceptions'!
5
+
6
+ !Error methodsFor: 'accessing'!
7
+
8
+ messageText
9
+ ^messageText
10
+ !
11
+
12
+ messageText: aString
13
+ messageText := aString
14
+ !
15
+
16
+ context
17
+ <return self.context>
18
+ !
19
+
20
+ jsStack
21
+ <return self.stack>
22
+ ! !
23
+
24
+ !Error methodsFor: 'signaling'!
25
+
26
+ signal
27
+ <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
28
+ ! !
29
+
30
+ !Error methodsFor: 'testing'!
31
+
32
+ isSmalltalkError
33
+ <return self.smalltalkError === true>
34
+ ! !
35
+
36
+ !Error class methodsFor: 'instance creation'!
37
+
38
+ signal: aString
39
+ ^self new
40
+ messageText: aString;
41
+ signal
42
+ ! !
43
+
44
+ Error subclass: #MessageNotUnderstood
45
+ instanceVariableNames: 'message receiver'
46
+ category: 'Kernel-Exceptions'!
47
+
48
+ !MessageNotUnderstood methodsFor: 'accessing'!
49
+
50
+ message
51
+ ^message
52
+ !
53
+
54
+ message: aMessage
55
+ message := aMessage
56
+ !
57
+
58
+ receiver
59
+ ^receiver
60
+ !
61
+
62
+ receiver: anObject
63
+ receiver := anObject
64
+ !
65
+
66
+ messageText
67
+ ^self receiver asString, ' does not understand #', self message selector
68
+ ! !
69
+
70
+ Object subclass: #ErrorHandler
71
+ instanceVariableNames: ''
72
+ category: 'Kernel-Exceptions'!
73
+
74
+ !ErrorHandler methodsFor: 'error handling'!
75
+
76
+ handleError: anError
77
+ anError context ifNotNil: [self logErrorContext: anError context].
78
+ self logError: anError
79
+ ! !
80
+
81
+ !ErrorHandler methodsFor: 'private'!
82
+
83
+ logContext: aContext
84
+ aContext home ifNotNil: [
85
+ self logContext: aContext home].
86
+ self log: aContext receiver asString, '>>', aContext selector
87
+ !
88
+
89
+ logErrorContext: aContext
90
+ aContext ifNotNil: [
91
+ aContext home ifNotNil: [
92
+ self logContext: aContext home]]
93
+ !
94
+
95
+ logError: anError
96
+ self log: anError messageText
97
+ !
98
+
99
+ log: aString
100
+ console log: aString
101
+ ! !
102
+
103
+ ErrorHandler class instanceVariableNames: 'current'!
104
+
105
+ !ErrorHandler class methodsFor: 'accessing'!
106
+
107
+ current
108
+ ^current ifNil: [current := self new]
109
+ !
110
+
111
+ setCurrent: anHandler
112
+ current := anHandler
113
+ ! !
114
+
115
+ !ErrorHandler class methodsFor: 'initialization'!
116
+
117
+ initialize
118
+ self register
119
+ !
120
+
121
+ register
122
+ ErrorHandler setCurrent: self new
123
+ ! !
124
+
@@ -0,0 +1,287 @@
1
+ Smalltalk current createPackage: 'Kernel-Methods' properties: #{}!
2
+ Object subclass: #CompiledMethod
3
+ instanceVariableNames: ''
4
+ category: 'Kernel-Methods'!
5
+ !CompiledMethod commentStamp!
6
+ CompiledMethod hold the source and compiled code of a class method.
7
+
8
+ You can get a CompiledMethod using `Behavior>>methodAt:`
9
+
10
+ String methodAt: 'lines'
11
+
12
+ and read the source code
13
+
14
+ (String methodAt: 'lines') source
15
+
16
+ See referenced classes:
17
+
18
+ (String methodAt: 'lines') referencedClasses
19
+
20
+ or messages sent from this method:
21
+
22
+ (String methodAt: 'lines') messageSends!
23
+
24
+ !CompiledMethod methodsFor: 'accessing'!
25
+
26
+ source
27
+ ^(self basicAt: 'source') ifNil: ['']
28
+ !
29
+
30
+ source: aString
31
+ self basicAt: 'source' put: aString
32
+ !
33
+
34
+ category
35
+ ^(self basicAt: 'category') ifNil: ['']
36
+ !
37
+
38
+ category: aString
39
+ self basicAt: 'category' put: aString
40
+ !
41
+
42
+ selector
43
+ ^self basicAt: 'selector'
44
+ !
45
+
46
+ selector: aString
47
+ self basicAt: 'selector' put: aString
48
+ !
49
+
50
+ fn
51
+ ^self basicAt: 'fn'
52
+ !
53
+
54
+ fn: aBlock
55
+ self basicAt: 'fn' put: aBlock
56
+ !
57
+
58
+ messageSends
59
+ ^self basicAt: 'messageSends'
60
+ !
61
+
62
+ methodClass
63
+ ^self basicAt: 'methodClass'
64
+ !
65
+
66
+ referencedClasses
67
+ ^self basicAt: 'referencedClasses'
68
+ !
69
+
70
+ arguments
71
+ <return self.args || []>
72
+ ! !
73
+
74
+ Object subclass: #BlockClosure
75
+ instanceVariableNames: ''
76
+ category: 'Kernel-Methods'!
77
+ !BlockClosure commentStamp!
78
+ A BlockClosure is a lexical closure.
79
+ The JavaScript representation is a function.
80
+
81
+ A BlockClosure is evaluated with the `#value*` methods in the 'evaluating' protocol.!
82
+
83
+ !BlockClosure methodsFor: 'accessing'!
84
+
85
+ compiledSource
86
+ <return self.toString()>
87
+ !
88
+
89
+ numArgs
90
+ <return self.length>
91
+ ! !
92
+
93
+ !BlockClosure methodsFor: 'controlling'!
94
+
95
+ whileTrue: aBlock
96
+ "inlined in the Compiler"
97
+ <while(self()) {aBlock()}>
98
+ !
99
+
100
+ whileFalse: aBlock
101
+ "inlined in the Compiler"
102
+ <while(!!self()) {aBlock()}>
103
+ !
104
+
105
+ whileFalse
106
+ "inlined in the Compiler"
107
+ self whileFalse: []
108
+ !
109
+
110
+ whileTrue
111
+ "inlined in the Compiler"
112
+ self whileTrue: []
113
+ ! !
114
+
115
+ !BlockClosure methodsFor: 'error handling'!
116
+
117
+ on: anErrorClass do: aBlock
118
+ ^self try: self catch: [:error |
119
+ (error isKindOf: anErrorClass)
120
+ ifTrue: [aBlock value: error]
121
+ ifFalse: [error signal]]
122
+ ! !
123
+
124
+ !BlockClosure methodsFor: 'evaluating'!
125
+
126
+ value
127
+ "inlined in the Compiler"
128
+ <return self();>
129
+ !
130
+
131
+ value: anArg
132
+ "inlined in the Compiler"
133
+ <return self(anArg);>
134
+ !
135
+
136
+ value: firstArg value: secondArg
137
+ "inlined in the Compiler"
138
+ <return self(firstArg, secondArg);>
139
+ !
140
+
141
+ value: firstArg value: secondArg value: thirdArg
142
+ "inlined in the Compiler"
143
+ <return self(firstArg, secondArg, thirdArg);>
144
+ !
145
+
146
+ valueWithPossibleArguments: aCollection
147
+ <return self.apply(null, aCollection);>
148
+ !
149
+
150
+ new
151
+ "Use the receiver as a JS constructor.
152
+ *Do not* use this method to instanciate Smalltalk objects!!"
153
+ <return new self()>
154
+ !
155
+
156
+ applyTo: anObject arguments: aCollection
157
+ <return self.apply(anObject, aCollection)>
158
+ !
159
+
160
+ timeToRun
161
+ "Answer the number of milliseconds taken to execute this block."
162
+
163
+ ^ Date millisecondsToRun: self
164
+ !
165
+
166
+ ensure: aBlock
167
+ | success |
168
+ success := false.
169
+ ^[self value. success := true. aBlock value]
170
+ on: Error
171
+ do: [:ex |
172
+ success ifFalse: [aBlock value].
173
+ ex signal]
174
+ !
175
+
176
+ newValue: anObject
177
+ "Use the receiver as a JS constructor.
178
+ *Do not* use this method to instanciate Smalltalk objects!!"
179
+ <return new self(anObject)>
180
+ !
181
+
182
+ newValue: anObject value: anObject2
183
+ "Use the receiver as a JS constructor.
184
+ *Do not* use this method to instanciate Smalltalk objects!!"
185
+ <return new self(anObject, anObject2)>
186
+ !
187
+
188
+ newValue: anObject value: anObject2 value: anObject3
189
+ "Use the receiver as a JS constructor.
190
+ *Do not* use this method to instanciate Smalltalk objects!!"
191
+ <return new self(anObject, anObject2)>
192
+ ! !
193
+
194
+ !BlockClosure methodsFor: 'timeout/interval'!
195
+
196
+ valueWithTimeout: aNumber
197
+ <return setTimeout(self, aNumber)>
198
+ !
199
+
200
+ valueWithInterval: aNumber
201
+ <return setInterval(self, aNumber)>
202
+ ! !
203
+
204
+ Object subclass: #MethodContext
205
+ instanceVariableNames: ''
206
+ category: 'Kernel-Methods'!
207
+ !MethodContext commentStamp!
208
+ MethodContext holds all the dynamic state associated with the execution of either a method activation resulting from a message send. That is used to build the call stack while debugging.
209
+
210
+ MethodContext instances are JavaScript `SmalltalkMethodContext` objects defined in boot.js
211
+
212
+ Current limitation: MethodContext instances are not created on Block evaluation. That means it's actually impossible to debug inside a Block.!
213
+
214
+ !MethodContext methodsFor: 'accessing'!
215
+
216
+ receiver
217
+ <return self.receiver>
218
+ !
219
+
220
+ selector
221
+ <return smalltalk.convertSelector(self.selector)>
222
+ !
223
+
224
+ home
225
+ <return self.homeContext>
226
+ !
227
+
228
+ temps
229
+ <return self.temps>
230
+ !
231
+
232
+ printString
233
+ ^super printString, '(', self asString, ')'
234
+ !
235
+
236
+ asString
237
+ ^self receiver class printString, ' >> ', self selector
238
+ ! !
239
+
240
+ Object subclass: #Message
241
+ instanceVariableNames: 'selector arguments'
242
+ category: 'Kernel-Methods'!
243
+ !Message commentStamp!
244
+ Generally, the system does not use instances of Message for efficiency reasons.
245
+ However, when a message is not understood by its receiver, the interpreter will make up an instance of it in order to capture the information involved in an actual message transmission.
246
+ This instance is sent it as an argument with the message `doesNotUnderstand:` to the receiver.
247
+
248
+ See boot.js, `messageNotUnderstood` and its counterpart `Object>>doesNotUnderstand:`!
249
+
250
+ !Message methodsFor: 'accessing'!
251
+
252
+ selector
253
+ ^selector
254
+ !
255
+
256
+ selector: aString
257
+ selector := aString
258
+ !
259
+
260
+ arguments: anArray
261
+ arguments := anArray
262
+ !
263
+
264
+ arguments
265
+ ^arguments
266
+ ! !
267
+
268
+ !Message methodsFor: 'printing'!
269
+
270
+ printString
271
+ ^ String streamContents: [:aStream|
272
+ aStream
273
+ nextPutAll: super printString;
274
+ nextPutAll: '(';
275
+ nextPutAll: selector;
276
+ nextPutAll: ')' ]
277
+ ! !
278
+
279
+ !Message class methodsFor: 'instance creation'!
280
+
281
+ selector: aString arguments: anArray
282
+ ^self new
283
+ selector: aString;
284
+ arguments: anArray;
285
+ yourself
286
+ ! !
287
+
@@ -0,0 +1,1489 @@
1
+ Smalltalk current createPackage: 'Kernel-Objects' properties: #{}!
2
+ nil subclass: #Object
3
+ instanceVariableNames: ''
4
+ category: 'Kernel-Objects'!
5
+ !Object commentStamp!
6
+ *Object is the root of the Smalltalk class system*. All classes in the system are subclasses of Object.
7
+
8
+ Object provides default behavior common to all normal objects, such as:
9
+
10
+ - access
11
+ - copying
12
+ - comparison
13
+ - error handling
14
+ - message sending
15
+ - reflection
16
+
17
+ Also utility messages that all objects should respond to are defined here.
18
+
19
+ Object has no instance variable.
20
+
21
+ ##Access
22
+
23
+ Instance variables can be accessed with `#instVarAt:` and `#instVarAt:put:`. `Object >> instanceVariableNames` answers a collection of all instance variable names.
24
+ Accessing JavaScript properties of an object is done through `#basicAt:`, `#basicAt:put:` and `basicDelete:`.
25
+
26
+ ##Copying
27
+
28
+ Copying an object is handled by `#copy` and `#deepCopy`. The first one performs a shallow copy of the receiver, while the second one performs a deep copy.
29
+ The hook method `#postCopy` can be overriden in subclasses to copy fields as necessary to complete the full copy. It will be sent by the copy of the receiver.
30
+
31
+ ##Comparison
32
+
33
+ Objects understand equality `#=` and identity `#==` comparison.
34
+
35
+ ##Error handling
36
+
37
+ - `#halt` is the typical message to use for inserting breakpoints during debugging.
38
+ - `#error:` throws a generic error exception
39
+ - `#doesNotUnderstand:` handles the fact that there was an attempt to send the given message to the receiver but the receiver does not understand this message.
40
+ Overriding this message can be useful to implement proxies for example.!
41
+
42
+ !Object methodsFor: 'accessing'!
43
+
44
+ yourself
45
+ ^self
46
+ !
47
+
48
+ class
49
+ <return self.klass>
50
+ !
51
+
52
+ size
53
+ self error: 'Object not indexable'
54
+ !
55
+
56
+ instVarAt: aSymbol
57
+ | varname |
58
+ varname := aSymbol asString.
59
+ <return self['@'+varname]>
60
+ !
61
+
62
+ instVarAt: aSymbol put: anObject
63
+ | varname |
64
+ varname := aSymbol asString.
65
+ <self['@' + varname] = anObject>
66
+ !
67
+
68
+ basicAt: aString
69
+ <return self[aString]>
70
+ !
71
+
72
+ basicAt: aString put: anObject
73
+ <return self[aString] = anObject>
74
+ !
75
+
76
+ basicDelete: aString
77
+ <delete self[aString]; return aString>
78
+ !
79
+
80
+ identityHash
81
+ <return self.identityHash || (self.identityHash = smalltalk.nextId());>
82
+ ! !
83
+
84
+ !Object methodsFor: 'comparing'!
85
+
86
+ = anObject
87
+ ^self == anObject
88
+ !
89
+
90
+ ~= anObject
91
+ ^(self = anObject) = false
92
+ !
93
+
94
+ == anObject
95
+ ^self identityHash = anObject identityHash
96
+ !
97
+
98
+ ~~ anObject
99
+ ^(self == anObject) = false
100
+ ! !
101
+
102
+ !Object methodsFor: 'converting'!
103
+
104
+ -> anObject
105
+ ^Association key: self value: anObject
106
+ !
107
+
108
+ asString
109
+ ^self printString
110
+ !
111
+
112
+ asJavascript
113
+ ^self asString
114
+ !
115
+
116
+ asJSON
117
+ ^JSON parse: self asJSONString
118
+ !
119
+
120
+ asJSONString
121
+ ^JSON stringify: self
122
+ ! !
123
+
124
+ !Object methodsFor: 'copying'!
125
+
126
+ copy
127
+ ^self shallowCopy postCopy
128
+ !
129
+
130
+ shallowCopy
131
+ <
132
+ var copy = self.klass._new();
133
+ for(var i in self) {
134
+ if(/^@.+/.test(i)) {
135
+ copy[i] = self[i];
136
+ }
137
+ }
138
+ return copy;
139
+ >
140
+ !
141
+
142
+ deepCopy
143
+ <
144
+ var copy = self.klass._new();
145
+ for(var i in self) {
146
+ if(/^@.+/.test(i)) {
147
+ copy[i] = self[i]._deepCopy();
148
+ }
149
+ }
150
+ return copy;
151
+ >
152
+ !
153
+
154
+ postCopy
155
+ ! !
156
+
157
+ !Object methodsFor: 'error handling'!
158
+
159
+ error: aString
160
+ Error signal: aString
161
+ !
162
+
163
+ subclassResponsibility
164
+ self error: 'This method is a responsibility of a subclass'
165
+ !
166
+
167
+ shouldNotImplement
168
+ self error: 'This method should not be implemented in ', self class name
169
+ !
170
+
171
+ try: aBlock catch: anotherBlock
172
+ <try{result = aBlock()} catch(e) {result = anotherBlock(e)};
173
+ return result;>
174
+ !
175
+
176
+ doesNotUnderstand: aMessage
177
+ MessageNotUnderstood new
178
+ receiver: self;
179
+ message: aMessage;
180
+ signal
181
+ !
182
+
183
+ halt
184
+ self error: 'Halt encountered'
185
+ !
186
+
187
+ deprecatedAPI
188
+ "Just a simple way to deprecate methods.
189
+ #deprecatedAPI is in the 'error handling' protocol even if it doesn't throw an error,
190
+ but it could in the future."
191
+ console warn: thisContext home asString, ' is deprecated!! (in ', thisContext home home asString, ')'
192
+ ! !
193
+
194
+ !Object methodsFor: 'initialization'!
195
+
196
+ initialize
197
+ ! !
198
+
199
+ !Object methodsFor: 'message handling'!
200
+
201
+ perform: aSymbol
202
+ ^self perform: aSymbol withArguments: #()
203
+ !
204
+
205
+ perform: aSymbol withArguments: aCollection
206
+ ^self basicPerform: aSymbol asSelector withArguments: aCollection
207
+ !
208
+
209
+ basicPerform: aSymbol
210
+ ^self basicPerform: aSymbol withArguments: #()
211
+ !
212
+
213
+ basicPerform: aSymbol withArguments: aCollection
214
+ <return self[aSymbol].apply(self, aCollection);>
215
+ ! !
216
+
217
+ !Object methodsFor: 'printing'!
218
+
219
+ printString
220
+ ^'a ', self class name
221
+ !
222
+
223
+ printNl
224
+ <console.log(self)>
225
+ !
226
+
227
+ log: aString block: aBlock
228
+
229
+ | result |
230
+ console log: aString, ' time: ', (Date millisecondsToRun: [result := aBlock value]) printString.
231
+ ^result
232
+ !
233
+
234
+ storeString
235
+ "Answer a String representation of the receiver from which the receiver
236
+ can be reconstructed."
237
+
238
+ ^ String streamContents: [:s | self storeOn: s]
239
+ !
240
+
241
+ storeOn: aStream
242
+ aStream nextPutAll: self printString
243
+ ! !
244
+
245
+ !Object methodsFor: 'testing'!
246
+
247
+ isKindOf: aClass
248
+ ^(self isMemberOf: aClass)
249
+ ifTrue: [true]
250
+ ifFalse: [self class inheritsFrom: aClass]
251
+ !
252
+
253
+ isMemberOf: aClass
254
+ ^self class = aClass
255
+ !
256
+
257
+ ifNil: aBlock
258
+ "inlined in the Compiler"
259
+ ^self
260
+ !
261
+
262
+ ifNil: aBlock ifNotNil: anotherBlock
263
+ "inlined in the Compiler"
264
+ ^anotherBlock value
265
+ !
266
+
267
+ ifNotNil: aBlock
268
+ "inlined in the Compiler"
269
+ ^aBlock value
270
+ !
271
+
272
+ ifNotNil: aBlock ifNil: anotherBlock
273
+ "inlined in the Compiler"
274
+ ^aBlock value
275
+ !
276
+
277
+ isNil
278
+ ^false
279
+ !
280
+
281
+ notNil
282
+ ^self isNil not
283
+ !
284
+
285
+ isClass
286
+ ^false
287
+ !
288
+
289
+ isMetaclass
290
+ ^false
291
+ !
292
+
293
+ isNumber
294
+ ^false
295
+ !
296
+
297
+ isString
298
+ ^false
299
+ !
300
+
301
+ isParseFailure
302
+ ^false
303
+ !
304
+
305
+ isSymbol
306
+ ^false
307
+ ! !
308
+
309
+ !Object class methodsFor: 'initialization'!
310
+
311
+ initialize
312
+ "no op"
313
+ ! !
314
+
315
+ Object subclass: #Smalltalk
316
+ instanceVariableNames: ''
317
+ category: 'Kernel-Objects'!
318
+ !Smalltalk commentStamp!
319
+ Smalltalk has only one instance, accessed with `Smalltalk current`.
320
+ It represents the global JavaScript variable `smalltalk` declared in `js/boot.js`.
321
+
322
+ The `smalltalk` object holds all class and packages defined in the system.
323
+
324
+ ## Classes
325
+
326
+ Classes can be accessed using the following methods:
327
+
328
+ - `#classes` answers the full list of Smalltalk classes in the system
329
+ - `#at:` answers a specific class of `nil`
330
+
331
+ ## Packages
332
+
333
+ Packages can be accessed using the following methods:
334
+
335
+ - `#packages` answers the full list of packages
336
+ - `#packageAt:` answers a specific class of `nil`
337
+
338
+ __note:__ classes and packages are accessed using strings, not symbols
339
+
340
+ ## Parsing
341
+
342
+ The `#parse:` method is used to parse Smalltalk source code.
343
+ It requires the `Compiler` package and the `js/parser.js` parser file in order to work!
344
+
345
+ !Smalltalk methodsFor: 'accessing'!
346
+
347
+ classes
348
+ <return self.classes()>
349
+ !
350
+
351
+ at: aString
352
+ <return self[aString]>
353
+ !
354
+
355
+ basicParse: aString
356
+ <return smalltalk.parser.parse(aString)>
357
+ !
358
+
359
+ parse: aString
360
+ | result |
361
+ self try: [result := self basicParse: aString] catch: [:ex | (self parseError: ex parsing: aString) signal].
362
+ ^result
363
+ !
364
+
365
+ parseError: anException parsing: aString
366
+ | row col message lines badLine code |
367
+ <row = anException.line;
368
+ col = anException.column;
369
+ message = anException.message;>.
370
+ lines := aString lines.
371
+ badLine := lines at: row.
372
+ badLine := (badLine copyFrom: 1 to: col - 1), ' ===>', (badLine copyFrom: col to: badLine size).
373
+ lines at: row put: badLine.
374
+ code := String streamContents: [:s |
375
+ lines withIndexDo: [:l :i |
376
+ s nextPutAll: i asString, ': ', l, String lf]].
377
+ ^ Error new messageText: ('Parse error on line ' , row , ' column ' , col , ' : ' , message , ' Below is code with line numbers and ===> marker inserted:' , String lf, code)
378
+ !
379
+
380
+ reservedWords
381
+ "JavaScript reserved words"
382
+ <return self.reservedWords>
383
+ !
384
+
385
+ readJSObject: anObject
386
+ <return self.readJSObject(anObject)>
387
+ ! !
388
+
389
+ !Smalltalk methodsFor: 'classes'!
390
+
391
+ removeClass: aClass
392
+ aClass isMetaclass ifTrue: [self error: aClass asString, ' is a Metaclass and cannot be removed!!'].
393
+ aClass methodDictionary values do: [:each |
394
+ aClass removeCompiledMethod: each].
395
+ aClass class methodDictionary values do: [:each |
396
+ aClass class removeCompiledMethod: each].
397
+ self basicDelete: aClass name
398
+ ! !
399
+
400
+ !Smalltalk methodsFor: 'packages'!
401
+
402
+ packages
403
+ "Return all Package instances in the system."
404
+
405
+ <return self.packages.all()>
406
+ !
407
+
408
+ packageAt: packageName
409
+ <return self.packages[packageName]>
410
+ !
411
+
412
+ packageAt: packageName ifAbsent: aBlock
413
+ ^(self packageAt: packageName) ifNil: aBlock
414
+ !
415
+
416
+ removePackage: packageName
417
+ "Removes a package and all its classes."
418
+
419
+ | pkg |
420
+ pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
421
+ pkg classes do: [:each |
422
+ self removeClass: each].
423
+ self deletePackage: packageName
424
+ !
425
+
426
+ renamePackage: packageName to: newName
427
+ "Rename a package."
428
+
429
+ | pkg |
430
+ pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
431
+ (self packageAt: newName) ifNotNil: [self error: 'Already exists a package called: ', newName].
432
+ <smalltalk.packages[newName] = smalltalk.packages[packageName]>.
433
+ pkg name: newName.
434
+ self deletePackage: packageName.
435
+ ! !
436
+
437
+ !Smalltalk methodsFor: 'private'!
438
+
439
+ createPackage: packageName
440
+ "Create and bind a new package with given name and return it."
441
+
442
+ <return smalltalk.addPackage(packageName, nil)>
443
+ !
444
+
445
+ deletePackage: packageName
446
+ "Deletes a package by deleting its binding, but does not check if it contains classes etc.
447
+ To remove a package, use #removePackage instead."
448
+
449
+ <delete smalltalk.packages[packageName]>
450
+ !
451
+
452
+ createPackage: packageName properties: aDict
453
+ "Create and bind a new package with given name and return it."
454
+
455
+ | object |
456
+ <object = {};>.
457
+ aDict keysAndValuesDo: [:key :value |
458
+ <object[key] = value>.
459
+ ].
460
+ <return smalltalk.addPackage(packageName, object)>
461
+ ! !
462
+
463
+ Smalltalk class instanceVariableNames: 'current'!
464
+
465
+ !Smalltalk class methodsFor: 'accessing'!
466
+
467
+ current
468
+ <return smalltalk>
469
+ ! !
470
+
471
+ Object subclass: #Package
472
+ instanceVariableNames: 'commitPathJs commitPathSt'
473
+ category: 'Kernel-Objects'!
474
+ !Package commentStamp!
475
+ A Package is similar to a "class category" typically found in other Smalltalks like Pharo or Squeak. Amber does not have class categories anymore, it had in the beginning but now each class in the system knows which package it belongs to.
476
+
477
+ A Package has a name, an Array of "requires", a comment and a Dictionary with other optional key value attributes. A Package can also be queried for its classes, but it will then resort to a reverse scan of all classes to find them.
478
+ Packages are manipulated through "Smalltalk current", like for example finding one based on a name:
479
+
480
+ Smalltalk current packageAt: 'Kernel'
481
+
482
+ ...but you can also use:
483
+
484
+ Package named: 'Kernel'
485
+
486
+ A Package differs slightly from a Monticello package which can span multiple class categories using a naming convention based on hyphenation. But just as in Monticello a Package supports "class extensions" so a Package
487
+ can define behaviors in foreign classes using a naming convention for method categories where the category starts with an asterisk and then the name of the owning package follows. This can easily be seen in for example class
488
+ String where the method category "*IDE" defines #inspectOn: which thus is a method belonging to the IDE package.
489
+
490
+ You can fetch a package from the server:
491
+
492
+ Package fetch: 'Additional-Examples'!
493
+
494
+ !Package methodsFor: 'accessing'!
495
+
496
+ name
497
+ <return self.pkgName>
498
+ !
499
+
500
+ name: aString
501
+ <self.pkgName = aString>
502
+ !
503
+
504
+ dependencies
505
+ ^self propertyAt: 'dependencies' ifAbsent: [#()]
506
+ !
507
+
508
+ dependencies: anArray
509
+ ^self propertyAt: 'dependencies' put: anArray
510
+ !
511
+
512
+ properties
513
+ ^Smalltalk current readJSObject: (self basicAt: 'properties')
514
+ !
515
+
516
+ properties: aDict
517
+ "We store it as a javascript object."
518
+
519
+ | object |
520
+ <object = {};>.
521
+ aDict keysAndValuesDo: [:key :value |
522
+ <object[key] = value>.
523
+ ].
524
+ <return self.properties = object>
525
+ !
526
+
527
+ commitPathJs
528
+ ^ commitPathJs ifNil: [self class defaultCommitPathJs]
529
+ !
530
+
531
+ commitPathJs: aString
532
+ commitPathJs := aString
533
+ !
534
+
535
+ commitPathSt
536
+ ^ commitPathSt ifNil: [self class defaultCommitPathSt]
537
+ !
538
+
539
+ commitPathSt: aString
540
+ commitPathSt := aString
541
+ ! !
542
+
543
+ !Package methodsFor: 'classes'!
544
+
545
+ classes
546
+ "We need to do a reverse scan."
547
+ ^Smalltalk current classes select: [:c | c package == self]
548
+ ! !
549
+
550
+ !Package methodsFor: 'printing'!
551
+
552
+ printString
553
+ ^self name
554
+ ! !
555
+
556
+ !Package methodsFor: 'private'!
557
+
558
+ propertiesAsJSON
559
+ <return JSON.stringify(self.properties)>
560
+ !
561
+
562
+ jsProperties
563
+ <return self.properties>
564
+ !
565
+
566
+ jsProperties: aJSObject
567
+ <return self.properties = aJSObject>
568
+ ! !
569
+
570
+ !Package methodsFor: 'properties'!
571
+
572
+ propertyAt: key
573
+
574
+ <return self.properties[key]>
575
+ !
576
+
577
+ propertyAt: key put: value
578
+
579
+ <return self.properties[key] = value>
580
+ !
581
+
582
+ propertyAt: key ifAbsent: block
583
+
584
+ ^(self propertyAt: key) ifNil: [block value]
585
+ ! !
586
+
587
+ Package class instanceVariableNames: 'defaultCommitPathJs defaultCommitPathSt'!
588
+
589
+ !Package class methodsFor: 'commit paths'!
590
+
591
+ defaultCommitPathJs
592
+ ^ defaultCommitPathJs ifNil: [ defaultCommitPathJs := 'js']
593
+ !
594
+
595
+ defaultCommitPathJs: aString
596
+ defaultCommitPathJs := aString
597
+ !
598
+
599
+ defaultCommitPathSt
600
+ ^ defaultCommitPathSt ifNil: [ defaultCommitPathSt := 'st']
601
+ !
602
+
603
+ defaultCommitPathSt: aString
604
+ defaultCommitPathSt := aString
605
+ !
606
+
607
+ resetCommitPaths
608
+ defaultCommitPathJs := nil.
609
+ defaultCommitPathSt := nil.
610
+ ! !
611
+
612
+ !Package class methodsFor: 'loading-storing'!
613
+
614
+ fetch: aPackageName prefix: aPrefix
615
+ jQuery getScript: (aPrefix , aPackageName , '.js') onSuccess: [ Package init: aPackageName ]
616
+ !
617
+
618
+ fetch: aPackageName
619
+ self fetch: aPackageName prefix: self defaultCommitPathJs, '/'
620
+ !
621
+
622
+ commitToLocalStorage: aPackageName
623
+ | key sourceCode |
624
+ key := 'smalltalk.packages.' , aPackageName.
625
+ sourceCode := Exporter new exportPackage: aPackageName.
626
+ <localStorage[key] = escape(sourceCode)>
627
+ !
628
+
629
+ init: aPackageName
630
+ (smalltalk classes select: [ :each | <each.pkg.pkgName == aPackageName> ])
631
+ do: [ :each | <smalltalk.init(each)> ];
632
+ do: [ :each | each initialize ]
633
+ ! !
634
+
635
+ !Package class methodsFor: 'not yet classified'!
636
+
637
+ named: aPackageName
638
+
639
+ ^Smalltalk current packageAt: aPackageName
640
+ !
641
+
642
+ named: aPackageName ifAbsent: aBlock
643
+
644
+ ^Smalltalk current packageAt: aPackageName ifAbsent: aBlock
645
+ ! !
646
+
647
+ Object subclass: #Number
648
+ instanceVariableNames: ''
649
+ category: 'Kernel-Objects'!
650
+ !Number commentStamp!
651
+ Number holds the most general methods for dealing with numbers.
652
+ Number is directly mapped to JavaScript Number.
653
+
654
+ Most arithmetic methods like `#+` `#/` `#-` `#max:` are directly inlined into javascript.
655
+
656
+ ##Enumerating
657
+ A Number can be used to evaluate a Block a fixed number of times:
658
+
659
+ 5 timesRepeat: [Transcript show: 'This will be printed 5 times'; cr].
660
+
661
+ 1 to: 5 do: [:aNumber| Transcript show: aNumber asString; cr].
662
+
663
+ 1 to: 10 by: 2 do: [:aNumber| Transcript show: aNumber asString; cr].!
664
+
665
+ !Number methodsFor: ''!
666
+
667
+
668
+ ! !
669
+
670
+ !Number methodsFor: 'accessing'!
671
+
672
+ identityHash
673
+ ^self asString, 'n'
674
+ ! !
675
+
676
+ !Number methodsFor: 'arithmetic'!
677
+
678
+ + aNumber
679
+ "Inlined in the Compiler"
680
+ <return self + aNumber>
681
+ !
682
+
683
+ - aNumber
684
+ "Inlined in the Compiler"
685
+ <return self - aNumber>
686
+ !
687
+
688
+ * aNumber
689
+ "Inlined in the Compiler"
690
+ <return self * aNumber>
691
+ !
692
+
693
+ / aNumber
694
+ "Inlined in the Compiler"
695
+ <return self / aNumber>
696
+ !
697
+
698
+ max: aNumber
699
+ <return Math.max(self, aNumber);>
700
+ !
701
+
702
+ min: aNumber
703
+ <return Math.min(self, aNumber);>
704
+ !
705
+
706
+ negated
707
+ ^0 - self
708
+ !
709
+
710
+ \\ aNumber
711
+ <return self % aNumber>
712
+ !
713
+
714
+ sqrt
715
+ <return Math.sqrt(self)>
716
+ !
717
+
718
+ squared
719
+ ^self * self
720
+ ! !
721
+
722
+ !Number methodsFor: 'comparing'!
723
+
724
+ = aNumber
725
+ aNumber isNumber ifFalse: [^false].
726
+ <return Number(self) == aNumber>
727
+ !
728
+
729
+ > aNumber
730
+ "Inlined in the Compiler"
731
+ <return self >> aNumber>
732
+ !
733
+
734
+ < aNumber
735
+ "Inlined in the Compiler"
736
+ <return self < aNumber>
737
+ !
738
+
739
+ >= aNumber
740
+ "Inlined in the Compiler"
741
+ <return self >>= aNumber>
742
+ !
743
+
744
+ <= aNumber
745
+ "Inlined in the Compiler"
746
+ <return self <= aNumber>
747
+ ! !
748
+
749
+ !Number methodsFor: 'converting'!
750
+
751
+ rounded
752
+ <return Math.round(self);>
753
+ !
754
+
755
+ truncated
756
+ |result|
757
+
758
+ self >= 0
759
+ ifTrue: [<result = Math.floor(self);>]
760
+ ifFalse: [<result = (Math.floor(self * (-1)) * (-1));>].
761
+
762
+ ^ result
763
+ !
764
+
765
+ to: aNumber
766
+ | array first last count |
767
+ first := self truncated.
768
+ last := aNumber truncated + 1.
769
+ count := 1.
770
+ array := Array new.
771
+ (last - first) timesRepeat: [
772
+ array at: count put: first.
773
+ count := count + 1.
774
+ first := first + 1].
775
+ ^array
776
+ !
777
+
778
+ asString
779
+ ^self printString
780
+ !
781
+
782
+ asJavascript
783
+ ^'(', self printString, ')'
784
+ !
785
+
786
+ atRandom
787
+ ^(Random new next * self) truncated + 1
788
+ !
789
+
790
+ @ aNumber
791
+ ^Point x: self y: aNumber
792
+ !
793
+
794
+ asPoint
795
+ ^Point x: self y: self
796
+ !
797
+
798
+ to: stop by: step
799
+ | array value pos |
800
+ value := self.
801
+ array := Array new.
802
+ pos := 1.
803
+ step = 0 ifTrue: [self error: 'step must be non-zero'].
804
+ step < 0
805
+ ifTrue: [[ value >= stop ] whileTrue: [
806
+ array at: pos put: value.
807
+ pos := pos + 1.
808
+ value := value + step]]
809
+ ifFalse: [[ value <= stop ] whileTrue: [
810
+ array at: pos put: value.
811
+ pos := pos + 1.
812
+ value := value + step]].
813
+ ^array
814
+ ! !
815
+
816
+ !Number methodsFor: 'copying'!
817
+
818
+ deepCopy
819
+ ^self copy
820
+ !
821
+
822
+ copy
823
+ ^self
824
+ ! !
825
+
826
+ !Number methodsFor: 'enumerating'!
827
+
828
+ timesRepeat: aBlock
829
+ | integer count |
830
+ integer := self truncated.
831
+ count := 1.
832
+ [count > self] whileFalse: [
833
+ aBlock value.
834
+ count := count + 1]
835
+ !
836
+
837
+ to: stop do: aBlock
838
+ "Evaluate aBlock for each number from self to aNumber."
839
+ | nextValue |
840
+ nextValue := self.
841
+ [nextValue <= stop]
842
+ whileTrue:
843
+ [aBlock value: nextValue.
844
+ nextValue := nextValue + 1]
845
+ !
846
+
847
+ to: stop by: step do: aBlock
848
+ | value |
849
+ value := self.
850
+ step = 0 ifTrue: [self error: 'step must be non-zero'].
851
+ step < 0
852
+ ifTrue: [[ value >= stop ] whileTrue: [
853
+ aBlock value: value.
854
+ value := value + step]]
855
+ ifFalse: [[ value <= stop ] whileTrue: [
856
+ aBlock value: value.
857
+ value := value + step]]
858
+ ! !
859
+
860
+ !Number methodsFor: 'printing'!
861
+
862
+ printString
863
+ <return String(self)>
864
+ !
865
+
866
+ printShowingDecimalPlaces: placesDesired
867
+ <return self.toFixed(placesDesired)>
868
+ ! !
869
+
870
+ !Number methodsFor: 'testing'!
871
+
872
+ isNumber
873
+ ^true
874
+ !
875
+
876
+ even
877
+ ^ 0 = (self \\ 2)
878
+ !
879
+
880
+ odd
881
+ ^ self even not
882
+ !
883
+
884
+ negative
885
+ "Answer whether the receiver is mathematically negative."
886
+
887
+ ^ self < 0
888
+ !
889
+
890
+ positive
891
+ "Answer whether the receiver is positive or equal to 0. (ST-80 protocol)."
892
+
893
+ ^ self >= 0
894
+ !
895
+
896
+ isZero
897
+ ^self = 0
898
+ ! !
899
+
900
+ !Number methodsFor: 'timeouts/intervals'!
901
+
902
+ clearInterval
903
+ <clearInterval(Number(self))>
904
+ !
905
+
906
+ clearTimeout
907
+ <clearTimeout(Number(self))>
908
+ ! !
909
+
910
+ !Number class methodsFor: 'instance creation'!
911
+
912
+ pi
913
+ <return Math.PI>
914
+ ! !
915
+
916
+ Object subclass: #Boolean
917
+ instanceVariableNames: ''
918
+ category: 'Kernel-Objects'!
919
+ !Boolean commentStamp!
920
+ Boolean wraps the JavaScript `Boolean()` constructor. The `true` and `false` objects are the JavaScript boolean objects.
921
+
922
+ Boolean defines the protocol for logic testing operations and conditional control structures for the logical values.
923
+ Boolean instances are weither `true` or `false`.!
924
+
925
+ !Boolean methodsFor: 'comparing'!
926
+
927
+ = aBoolean
928
+ aBoolean class = self class ifFalse: [^false].
929
+ <return Boolean(self == true) == aBoolean>
930
+ ! !
931
+
932
+ !Boolean methodsFor: 'controlling'!
933
+
934
+ ifTrue: aBlock
935
+ "inlined in the Compiler"
936
+ ^self ifTrue: aBlock ifFalse: []
937
+ !
938
+
939
+ ifFalse: aBlock
940
+ "inlined in the Compiler"
941
+ ^self ifTrue: [] ifFalse: aBlock
942
+ !
943
+
944
+ ifFalse: aBlock ifTrue: anotherBlock
945
+ "inlined in the Compiler"
946
+ ^self ifTrue: anotherBlock ifFalse: aBlock
947
+ !
948
+
949
+ ifTrue: aBlock ifFalse: anotherBlock
950
+ "inlined in the Compiler"
951
+ <
952
+ if(self == true) {
953
+ return aBlock();
954
+ } else {
955
+ return anotherBlock();
956
+ }
957
+ >
958
+ !
959
+
960
+ and: aBlock
961
+ ^self = true
962
+ ifTrue: aBlock
963
+ ifFalse: [false]
964
+ !
965
+
966
+ or: aBlock
967
+ ^self = true
968
+ ifTrue: [true]
969
+ ifFalse: aBlock
970
+ !
971
+
972
+ not
973
+ ^self = false
974
+ !
975
+
976
+ & aBoolean
977
+ <
978
+ if(self == true) {
979
+ return aBoolean;
980
+ } else {
981
+ return false;
982
+ }
983
+ >
984
+ !
985
+
986
+ | aBoolean
987
+ <
988
+ if(self == true) {
989
+ return true;
990
+ } else {
991
+ return aBoolean;
992
+ }
993
+ >
994
+ ! !
995
+
996
+ !Boolean methodsFor: 'copying'!
997
+
998
+ shallowCopy
999
+ ^self
1000
+ !
1001
+
1002
+ deepCopy
1003
+ ^self
1004
+ ! !
1005
+
1006
+ !Boolean methodsFor: 'printing'!
1007
+
1008
+ printString
1009
+ <return self.toString()>
1010
+ ! !
1011
+
1012
+ Object subclass: #Date
1013
+ instanceVariableNames: ''
1014
+ category: 'Kernel-Objects'!
1015
+ !Date commentStamp!
1016
+ The Date class is used to work with dates and times. Therefore `Date today` and `Date now` are both valid in
1017
+ Amber and answer the same date object.
1018
+
1019
+ Date wraps the `Date()` JavaScript constructor, and Smalltalk date objects are JavaScript date objects.!
1020
+
1021
+ !Date methodsFor: 'accessing'!
1022
+
1023
+ year
1024
+ <return self.getFullYear()>
1025
+ !
1026
+
1027
+ month
1028
+ <return self.getMonth() + 1>
1029
+ !
1030
+
1031
+ month: aNumber
1032
+ <self.setMonth(aNumber - 1)>
1033
+ !
1034
+
1035
+ day
1036
+ ^self dayOfWeek
1037
+ !
1038
+
1039
+ dayOfWeek
1040
+ <return self.getDay() + 1>
1041
+ !
1042
+
1043
+ dayOfWeek: aNumber
1044
+ <return self.setDay(aNumber - 1)>
1045
+ !
1046
+
1047
+ day: aNumber
1048
+ self day: aNumber
1049
+ !
1050
+
1051
+ year: aNumber
1052
+ <self.setFullYear(aNumber)>
1053
+ !
1054
+
1055
+ dayOfMonth
1056
+ <return self.getDate()>
1057
+ !
1058
+
1059
+ dayOfMonth: aNumber
1060
+ <self.setDate(aNumber)>
1061
+ !
1062
+
1063
+ time
1064
+ <return self.getTime()>
1065
+ !
1066
+
1067
+ time: aNumber
1068
+ <self.setTime(aNumber)>
1069
+ !
1070
+
1071
+ hours: aNumber
1072
+ <self.setHours(aNumber)>
1073
+ !
1074
+
1075
+ minutes: aNumber
1076
+ <self.setMinutes(aNumber)>
1077
+ !
1078
+
1079
+ seconds: aNumber
1080
+ <self.setSeconds(aNumber)>
1081
+ !
1082
+
1083
+ milliseconds: aNumber
1084
+ <self.setMilliseconds(aNumber)>
1085
+ !
1086
+
1087
+ hours
1088
+ <return self.getHours()>
1089
+ !
1090
+
1091
+ minutes
1092
+ <return self.getMinutes()>
1093
+ !
1094
+
1095
+ seconds
1096
+ <return self.getSeconds()>
1097
+ !
1098
+
1099
+ milliseconds
1100
+ <return self.getMilliseconds()>
1101
+ ! !
1102
+
1103
+ !Date methodsFor: 'arithmetic'!
1104
+
1105
+ - aDate
1106
+ <return self - aDate>
1107
+ !
1108
+
1109
+ + aDate
1110
+ <return self + aDate>
1111
+ ! !
1112
+
1113
+ !Date methodsFor: 'comparing'!
1114
+
1115
+ < aDate
1116
+ <return self < aDate>
1117
+ !
1118
+
1119
+ > aDate
1120
+ <return self >> aDate>
1121
+ !
1122
+
1123
+ <= aDate
1124
+ <return self <= aDate>
1125
+ !
1126
+
1127
+ >= aDate
1128
+ <return self >>= aDate>
1129
+ ! !
1130
+
1131
+ !Date methodsFor: 'converting'!
1132
+
1133
+ asString
1134
+ <return self.toString()>
1135
+ !
1136
+
1137
+ asMilliseconds
1138
+ ^self time
1139
+ !
1140
+
1141
+ asDateString
1142
+ <return self.toDateString()>
1143
+ !
1144
+
1145
+ asTimeString
1146
+ <return self.toTimeString()>
1147
+ !
1148
+
1149
+ asLocaleString
1150
+ <return self.toLocaleString()>
1151
+ !
1152
+
1153
+ asNumber
1154
+ ^self asMilliseconds
1155
+ ! !
1156
+
1157
+ !Date methodsFor: 'printing'!
1158
+
1159
+ printString
1160
+ ^self asString
1161
+ ! !
1162
+
1163
+ !Date class methodsFor: 'instance creation'!
1164
+
1165
+ new: anObject
1166
+ <return new Date(anObject)>
1167
+ !
1168
+
1169
+ fromString: aString
1170
+ "Example: Date fromString('2011/04/15 00:00:00')"
1171
+ ^self new: aString
1172
+ !
1173
+
1174
+ fromSeconds: aNumber
1175
+ ^self fromMilliseconds: aNumber * 1000
1176
+ !
1177
+
1178
+ fromMilliseconds: aNumber
1179
+ ^self new: aNumber
1180
+ !
1181
+
1182
+ today
1183
+ ^self new
1184
+ !
1185
+
1186
+ now
1187
+ ^self today
1188
+ !
1189
+
1190
+ millisecondsToRun: aBlock
1191
+ | t |
1192
+ t := Date now.
1193
+ aBlock value.
1194
+ ^Date now - t
1195
+ ! !
1196
+
1197
+ Object subclass: #UndefinedObject
1198
+ instanceVariableNames: ''
1199
+ category: 'Kernel-Objects'!
1200
+ !UndefinedObject commentStamp!
1201
+ UndefinedObject describes the behavior of its sole instance, `nil`. `nil` represents a prior value for variables that have not been initialized, or for results which are meaningless.
1202
+
1203
+ `nil` is the Smalltalk representation of the `undefined` JavaScript object.!
1204
+
1205
+ !UndefinedObject methodsFor: 'class creation'!
1206
+
1207
+ subclass: aString instanceVariableNames: anotherString
1208
+ ^self subclass: aString instanceVariableNames: anotherString package: nil
1209
+ !
1210
+
1211
+ subclass: aString instanceVariableNames: aString2 category: aString3
1212
+ "Kept for compatibility."
1213
+ self deprecatedAPI.
1214
+ ^self subclass: aString instanceVariableNames: aString2 package: aString3
1215
+ !
1216
+
1217
+ subclass: aString instanceVariableNames: aString2 package: aString3
1218
+ ^ClassBuilder new
1219
+ superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
1220
+ ! !
1221
+
1222
+ !UndefinedObject methodsFor: 'copying'!
1223
+
1224
+ shallowCopy
1225
+ ^self
1226
+ !
1227
+
1228
+ deepCopy
1229
+ ^self
1230
+ ! !
1231
+
1232
+ !UndefinedObject methodsFor: 'printing'!
1233
+
1234
+ printString
1235
+ ^'nil'
1236
+ ! !
1237
+
1238
+ !UndefinedObject methodsFor: 'testing'!
1239
+
1240
+ ifNil: aBlock
1241
+ "inlined in the Compiler"
1242
+ ^self ifNil: aBlock ifNotNil: []
1243
+ !
1244
+
1245
+ ifNotNil: aBlock
1246
+ "inlined in the Compiler"
1247
+ ^self
1248
+ !
1249
+
1250
+ ifNil: aBlock ifNotNil: anotherBlock
1251
+ "inlined in the Compiler"
1252
+ ^aBlock value
1253
+ !
1254
+
1255
+ ifNotNil: aBlock ifNil: anotherBlock
1256
+ "inlined in the Compiler"
1257
+ ^anotherBlock value
1258
+ !
1259
+
1260
+ isNil
1261
+ ^true
1262
+ !
1263
+
1264
+ notNil
1265
+ ^false
1266
+ ! !
1267
+
1268
+ !UndefinedObject class methodsFor: 'instance creation'!
1269
+
1270
+ new
1271
+ self error: 'You cannot create new instances of UndefinedObject. Use nil'
1272
+ ! !
1273
+
1274
+ Object subclass: #Random
1275
+ instanceVariableNames: ''
1276
+ category: 'Kernel-Objects'!
1277
+ !Random commentStamp!
1278
+ `Random` is a random number generator and is implemented as a trivial wrapper around javascript `Math.random()` and is used like this:
1279
+
1280
+ Random new next
1281
+
1282
+ This will return a float x where x < 1 and x > 0. If you want a random integer from 1 to 10 you can use `#atRandom`
1283
+
1284
+ 10 atRandom
1285
+
1286
+ ...and if you want a random number in a specific interval this also works:
1287
+
1288
+ (3 to: 7) atRandom
1289
+
1290
+ ...but be aware that `#to:` does not create an Interval as in other Smalltalk implementations but in fact an `Array` of numbers, so it's better to use:
1291
+
1292
+ 5 atRandom + 2
1293
+
1294
+ Since `#atRandom` is implemented in `SequencableCollection` you can easy pick an element at random:
1295
+
1296
+ #('a' 'b' 'c') atRandom
1297
+
1298
+ ...or perhaps a letter from a `String`:
1299
+
1300
+ 'abc' atRandom
1301
+
1302
+ Since Amber does not have Characters this will return a `String` of length 1 like for example `'b'`.!
1303
+
1304
+ !Random methodsFor: 'accessing'!
1305
+
1306
+ next
1307
+ <return Math.random()>
1308
+ !
1309
+
1310
+ next: anInteger
1311
+ ^(1 to: anInteger) collect: [:each | self next]
1312
+ ! !
1313
+
1314
+ Object subclass: #Point
1315
+ instanceVariableNames: 'x y'
1316
+ category: 'Kernel-Objects'!
1317
+ !Point commentStamp!
1318
+ A `Point` represents an x-y pair of numbers usually designating a geometric coordinate.
1319
+ Points are traditionally created using the binary `#@` message to a number:
1320
+
1321
+ 100@120
1322
+
1323
+ Points can then be arithmetically manipulated:
1324
+
1325
+ 100@100 + (10@10)
1326
+
1327
+ ...or for example:
1328
+
1329
+ (100@100) * 2
1330
+
1331
+ **NOTE:** Creating a Point with a negative y-value will need a space after `@` in order to avoid a parsing error:
1332
+
1333
+ 100@ -100 "but 100@-100 would not parse"
1334
+
1335
+ Amber does not have much behavior in this class out-of-the-box.!
1336
+
1337
+ !Point methodsFor: 'accessing'!
1338
+
1339
+ x
1340
+ ^x
1341
+ !
1342
+
1343
+ y
1344
+ ^y
1345
+ !
1346
+
1347
+ y: aNumber
1348
+ y := aNumber
1349
+ !
1350
+
1351
+ x: aNumber
1352
+ x := aNumber
1353
+ ! !
1354
+
1355
+ !Point methodsFor: 'arithmetic'!
1356
+
1357
+ * aPoint
1358
+ ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
1359
+ !
1360
+
1361
+ + aPoint
1362
+ ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
1363
+ !
1364
+
1365
+ - aPoint
1366
+ ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
1367
+ !
1368
+
1369
+ / aPoint
1370
+ ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
1371
+ !
1372
+
1373
+ = aPoint
1374
+ ^aPoint class = self class and: [
1375
+ (aPoint x = self x) & (aPoint y = self y)]
1376
+ ! !
1377
+
1378
+ !Point methodsFor: 'converting'!
1379
+
1380
+ asPoint
1381
+ ^self
1382
+ ! !
1383
+
1384
+ !Point methodsFor: 'printing'!
1385
+
1386
+ printString
1387
+ "Print receiver in classic x@y notation."
1388
+
1389
+ ^String streamContents: [:stream |
1390
+ stream nextPutAll: x printString, '@'.
1391
+ (y notNil and: [y negative])
1392
+ ifTrue: [
1393
+ "Avoid ambiguous @- construct"
1394
+ stream space].
1395
+ stream nextPutAll: y printString]
1396
+ ! !
1397
+
1398
+ !Point class methodsFor: 'instance creation'!
1399
+
1400
+ x: aNumber y: anotherNumber
1401
+ ^self new
1402
+ x: aNumber;
1403
+ y: anotherNumber;
1404
+ yourself
1405
+ ! !
1406
+
1407
+ Object subclass: #JSObjectProxy
1408
+ instanceVariableNames: 'jsObject'
1409
+ category: 'Kernel-Objects'!
1410
+ !JSObjectProxy commentStamp!
1411
+ JSObjectProxy handles sending messages to JavaScript object, therefore accessing JavaScript objects from Amber is transparent.
1412
+ JSOjbectProxy makes intensive use of `#doesNotUnderstand:`.
1413
+
1414
+ ## Examples
1415
+
1416
+ JSObjectProxy objects are instanciated by Amber when a Smalltalk message is sent to a JavaScript object.
1417
+
1418
+ window alert: 'hello world'.
1419
+ window inspect.
1420
+ (window jQuery: 'body') append: 'hello world'
1421
+
1422
+ Smalltalk messages sends are converted to JavaScript function calls or object property access _(in this order)_. If n one of them match, a `MessageNotUnderstood` error will be thrown.
1423
+
1424
+ ## Message conversion rules
1425
+
1426
+ - `someUser name` becomes `someUser.name`
1427
+ - `someUser name: 'John'` becomes `someUser name = "John"`
1428
+ - `console log: 'hello world'` becomes `console.log('hello world')`
1429
+ - `(window jQuery: 'foo') css: 'background' color: 'red'` becomes `window.jQuery('foo').css('background', 'red')`
1430
+
1431
+ __Note:__ For keyword-based messages, only the first keyword is kept: `window foo: 1 bar: 2` is equivalent to `window foo: 1 baz: 2`.!
1432
+
1433
+ !JSObjectProxy methodsFor: 'accessing'!
1434
+
1435
+ jsObject: aJSObject
1436
+ jsObject := aJSObject
1437
+ !
1438
+
1439
+ jsObject
1440
+ ^jsObject
1441
+ !
1442
+
1443
+ at: aSymbol
1444
+ | attr |
1445
+ attr := aSymbol asString.
1446
+ <return self['@jsObject'][attr]>
1447
+ !
1448
+
1449
+ at: aSymbol put: anObject
1450
+ | attr |
1451
+ attr := aSymbol asString.
1452
+ <self['@jsObject'][attr] = anObject>
1453
+ ! !
1454
+
1455
+ !JSObjectProxy methodsFor: 'proxy'!
1456
+
1457
+ printString
1458
+ ^self jsObject toString
1459
+ !
1460
+
1461
+ inspectOn: anInspector
1462
+ | variables |
1463
+ variables := Dictionary new.
1464
+ variables at: '#self' put: self jsObject.
1465
+ anInspector setLabel: self printString.
1466
+ <for(var i in self['@jsObject']) {
1467
+ variables._at_put_(i, self['@jsObject'][i]);
1468
+ }>.
1469
+ anInspector setVariables: variables
1470
+ !
1471
+
1472
+ doesNotUnderstand: aMessage
1473
+ | obj selector jsSelector arguments |
1474
+ obj := self jsObject.
1475
+ selector := aMessage selector.
1476
+ jsSelector := selector asJavaScriptSelector.
1477
+ arguments := aMessage arguments.
1478
+ <if(obj[jsSelector] !!= undefined) {return smalltalk.send(obj, jsSelector, arguments)}>.
1479
+ super doesNotUnderstand: aMessage
1480
+ ! !
1481
+
1482
+ !JSObjectProxy class methodsFor: 'instance creation'!
1483
+
1484
+ on: aJSObject
1485
+ ^self new
1486
+ jsObject: aJSObject;
1487
+ yourself
1488
+ ! !
1489
+