Kernel-Methods.st 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  1. Smalltalk createPackage: 'Kernel-Methods'!
  2. Object subclass: #BlockClosure
  3. instanceVariableNames: ''
  4. package: 'Kernel-Methods'!
  5. !BlockClosure commentStamp!
  6. I represent a lexical closure.
  7. I am is directly mapped to JavaScript Function.
  8. ## API
  9. 1. Evaluation
  10. My instances get evaluated with the `#value*` methods in the 'evaluating' protocol.
  11. Example: ` [ :x | x + 1 ] value: 3 "Answers 4" `
  12. 2. Control structures
  13. Blocks are used (together with `Boolean`) for control structures (methods in the `controlling` protocol).
  14. Example: `aBlock whileTrue: [ ... ]`
  15. 3. Error handling
  16. I provide the `#on:do:` method for handling exceptions.
  17. Example: ` aBlock on: MessageNotUnderstood do: [ :ex | ... ] `!
  18. !BlockClosure methodsFor: 'accessing'!
  19. compiledSource
  20. <return self.toString()>
  21. !
  22. numArgs
  23. <return self.length>
  24. !
  25. receiver
  26. ^ nil
  27. ! !
  28. !BlockClosure methodsFor: 'controlling'!
  29. whileFalse
  30. self whileFalse: []
  31. !
  32. whileFalse: aBlock
  33. <while(!!$core.assert(self._value())) {aBlock._value()}>
  34. !
  35. whileTrue
  36. self whileTrue: []
  37. !
  38. whileTrue: aBlock
  39. <while($core.assert(self._value())) {aBlock._value()}>
  40. ! !
  41. !BlockClosure methodsFor: 'converting'!
  42. asCompiledMethod: aString
  43. <return $core.method({selector:aString, fn:self});>
  44. !
  45. currySelf
  46. "Transforms [ :selfarg :x :y | stcode ] block
  47. which represents JS function (selfarg, x, y, ...) {jscode}
  48. into function (x, y, ...) {jscode} that takes selfarg from 'this'.
  49. IOW, it is usable as JS method and first arg takes the receiver."
  50. <
  51. return function () {
  52. var args = [ this ];
  53. args.push.apply(args, arguments);
  54. return self.apply(null, args);
  55. }
  56. >
  57. ! !
  58. !BlockClosure methodsFor: 'error handling'!
  59. on: anErrorClass do: aBlock
  60. "All exceptions thrown in the Smalltalk stack are cought.
  61. Convert all JS exceptions to JavaScriptException instances."
  62. ^ self tryCatch: [ :error | | smalltalkError |
  63. smalltalkError := Smalltalk asSmalltalkException: error.
  64. (smalltalkError isKindOf: anErrorClass)
  65. ifTrue: [ aBlock value: smalltalkError ]
  66. ifFalse: [ smalltalkError resignal ] ]
  67. !
  68. tryCatch: aBlock
  69. <
  70. try {
  71. return self._value();
  72. } catch(error) {
  73. return aBlock._value_(error);
  74. }
  75. >
  76. ! !
  77. !BlockClosure methodsFor: 'evaluating'!
  78. applyTo: anObject arguments: aCollection
  79. <return self.apply(anObject, aCollection)>
  80. !
  81. ensure: aBlock
  82. <try{return self._value()}finally{aBlock._value()}>
  83. !
  84. new
  85. "Use the receiver as a JS constructor.
  86. *Do not* use this method to instanciate Smalltalk objects!!"
  87. <return new self()>
  88. !
  89. newValue: anObject
  90. ^ self newWithValues: { anObject }
  91. !
  92. newValue: anObject value: anObject2
  93. ^ self newWithValues: { anObject. anObject2 }.
  94. !
  95. newValue: anObject value: anObject2 value: anObject3
  96. ^ self newWithValues: { anObject. anObject2. anObject3 }.
  97. !
  98. newWithValues: aCollection
  99. "Simulates JS new operator by combination of Object.create and .apply"
  100. <
  101. var object = Object.create(self.prototype);
  102. var result = self.apply(object, aCollection);
  103. return typeof result === "object" ? result : object;
  104. >
  105. !
  106. timeToRun
  107. "Answer the number of milliseconds taken to execute this block."
  108. ^ Date millisecondsToRun: self
  109. !
  110. value
  111. <return self();>
  112. !
  113. value: anArg
  114. <return self(anArg);>
  115. !
  116. value: firstArg value: secondArg
  117. <return self(firstArg, secondArg);>
  118. !
  119. value: firstArg value: secondArg value: thirdArg
  120. <return self(firstArg, secondArg, thirdArg);>
  121. !
  122. valueWithPossibleArguments: aCollection
  123. <return self.apply(null, aCollection);>
  124. ! !
  125. !BlockClosure methodsFor: 'timeout/interval'!
  126. fork
  127. ForkPool default fork: self
  128. !
  129. valueWithInterval: aNumber
  130. <
  131. var interval = setInterval(self, aNumber);
  132. return $globals.Timeout._on_(interval);
  133. >
  134. !
  135. valueWithTimeout: aNumber
  136. <
  137. var timeout = setTimeout(self, aNumber);
  138. return $globals.Timeout._on_(timeout);
  139. >
  140. ! !
  141. Object subclass: #CompiledMethod
  142. instanceVariableNames: ''
  143. package: 'Kernel-Methods'!
  144. !CompiledMethod commentStamp!
  145. I represent a class method of the system. I hold the source and compiled code of a class method.
  146. ## API
  147. My instances can be accessed using `Behavior >> #methodAt:`
  148. Object methodAt: 'asString'
  149. Source code access:
  150. (String methodAt: 'lines') source
  151. Referenced classes:
  152. (String methodAt: 'lines') referencedClasses
  153. Messages sent from an instance:
  154. (String methodAt: 'lines') messageSends!
  155. !CompiledMethod methodsFor: 'accessing'!
  156. arguments
  157. <return self.args || []>
  158. !
  159. category
  160. ^ self protocol
  161. !
  162. fn
  163. ^ self basicAt: 'fn'
  164. !
  165. fn: aBlock
  166. self basicAt: 'fn' put: aBlock
  167. !
  168. messageSends
  169. ^ self basicAt: 'messageSends'
  170. !
  171. methodClass
  172. ^ self basicAt: 'methodClass'
  173. !
  174. package
  175. "Answer the package the receiver belongs to:
  176. - if it is an extension method, answer the corresponding package
  177. - else answer the `methodClass` package"
  178. ^ self methodClass ifNotNil: [ :class | class packageOfProtocol: self protocol ]
  179. !
  180. protocol
  181. ^ (self basicAt: 'protocol') ifNil: [ self defaultProtocol ]
  182. !
  183. protocol: aString
  184. | oldProtocol |
  185. oldProtocol := self protocol.
  186. self basicAt: 'protocol' put: aString.
  187. SystemAnnouncer current announce: (MethodMoved new
  188. method: self;
  189. oldProtocol: oldProtocol;
  190. yourself).
  191. self methodClass ifNotNil: [ :methodClass |
  192. methodClass organization addElement: aString.
  193. methodClass removeProtocolIfEmpty: oldProtocol ]
  194. !
  195. referencedClasses
  196. ^ self basicAt: 'referencedClasses'
  197. !
  198. selector
  199. ^ self basicAt: 'selector'
  200. !
  201. selector: aString
  202. self basicAt: 'selector' put: aString
  203. !
  204. source
  205. ^ (self basicAt: 'source') ifNil: [ '' ]
  206. !
  207. source: aString
  208. self basicAt: 'source' put: aString
  209. ! !
  210. !CompiledMethod methodsFor: 'browsing'!
  211. browse
  212. Finder findMethod: self
  213. ! !
  214. !CompiledMethod methodsFor: 'defaults'!
  215. defaultProtocol
  216. ^ 'as yet unclassified'
  217. ! !
  218. !CompiledMethod methodsFor: 'evaluating'!
  219. sendTo: anObject arguments: aCollection
  220. ^ self fn applyTo: anObject arguments: aCollection
  221. ! !
  222. !CompiledMethod methodsFor: 'testing'!
  223. isCompiledMethod
  224. ^ true
  225. !
  226. isOverridden
  227. | selector |
  228. selector := self selector.
  229. self methodClass allSubclassesDo: [ :each |
  230. (each includesSelector: selector)
  231. ifTrue: [ ^ true ] ].
  232. ^ false
  233. !
  234. isOverride
  235. | superclass |
  236. superclass := self methodClass superclass.
  237. superclass ifNil: [ ^ false ].
  238. ^ (self methodClass superclass lookupSelector: self selector) notNil
  239. ! !
  240. Object subclass: #ForkPool
  241. instanceVariableNames: 'poolSize maxPoolSize queue worker'
  242. package: 'Kernel-Methods'!
  243. !ForkPool commentStamp!
  244. I am responsible for handling forked blocks.
  245. The pool size sets the maximum concurrent forked blocks.
  246. ## API
  247. The default instance is accessed with `#default`.
  248. The maximum concurrent forked blocks can be set with `#maxPoolSize:`.
  249. Forking is done via `BlockClosure >> #fork`!
  250. !ForkPool methodsFor: 'accessing'!
  251. maxPoolSize
  252. ^ maxPoolSize ifNil: [ self defaultMaxPoolSize ]
  253. !
  254. maxPoolSize: anInteger
  255. maxPoolSize := anInteger
  256. ! !
  257. !ForkPool methodsFor: 'actions'!
  258. fork: aBlock
  259. poolSize < self maxPoolSize ifTrue: [ self addWorker ].
  260. queue nextPut: aBlock
  261. ! !
  262. !ForkPool methodsFor: 'defaults'!
  263. defaultMaxPoolSize
  264. ^ self class defaultMaxPoolSize
  265. ! !
  266. !ForkPool methodsFor: 'initialization'!
  267. initialize
  268. super initialize.
  269. poolSize := 0.
  270. queue := Queue new.
  271. worker := self makeWorker
  272. !
  273. makeWorker
  274. | sentinel |
  275. sentinel := Object new.
  276. ^ [ | block |
  277. poolSize := poolSize - 1.
  278. block := queue nextIfAbsent: [ sentinel ].
  279. block == sentinel ifFalse: [
  280. [ block value ] ensure: [ self addWorker ] ]]
  281. ! !
  282. !ForkPool methodsFor: 'private'!
  283. addWorker
  284. worker valueWithTimeout: 0.
  285. poolSize := poolSize + 1
  286. ! !
  287. ForkPool class instanceVariableNames: 'default'!
  288. !ForkPool class methodsFor: 'accessing'!
  289. default
  290. ^ default ifNil: [ default := self new ]
  291. !
  292. defaultMaxPoolSize
  293. ^ 100
  294. !
  295. resetDefault
  296. default := nil
  297. ! !
  298. Object subclass: #Message
  299. instanceVariableNames: 'selector arguments'
  300. package: 'Kernel-Methods'!
  301. !Message commentStamp!
  302. In general, the system does not use instances of me for efficiency reasons.
  303. 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.
  304. This instance is sent it as an argument with the message `#doesNotUnderstand:` to the receiver.
  305. See boot.js, `messageNotUnderstood` and its counterpart `Object >> #doesNotUnderstand:`
  306. ## API
  307. Besides accessing methods, `#sendTo:` provides a convenient way to send a message to an object.!
  308. !Message methodsFor: 'accessing'!
  309. arguments
  310. ^ arguments
  311. !
  312. arguments: anArray
  313. arguments := anArray
  314. !
  315. selector
  316. ^ selector
  317. !
  318. selector: aString
  319. selector := aString
  320. ! !
  321. !Message methodsFor: 'actions'!
  322. sendTo: anObject
  323. ^ anObject perform: self selector withArguments: self arguments
  324. ! !
  325. !Message methodsFor: 'printing'!
  326. printOn: aStream
  327. super printOn: aStream.
  328. aStream
  329. nextPutAll: '(';
  330. nextPutAll: self selector;
  331. nextPutAll: ')'
  332. ! !
  333. !Message class methodsFor: 'instance creation'!
  334. selector: aString arguments: anArray
  335. ^ self new
  336. selector: aString;
  337. arguments: anArray;
  338. yourself
  339. ! !
  340. Object subclass: #MessageSend
  341. instanceVariableNames: 'receiver message'
  342. package: 'Kernel-Methods'!
  343. !MessageSend commentStamp!
  344. I encapsulate message sends to objects. Arguments can be either predefined or supplied when the message send is performed.
  345. ## API
  346. Use `#value` to perform a message send with its predefined arguments and `#value:*` if additonal arguments have to supplied.!
  347. !MessageSend methodsFor: 'accessing'!
  348. arguments
  349. ^ message arguments
  350. !
  351. arguments: aCollection
  352. message arguments: aCollection
  353. !
  354. receiver
  355. ^ receiver
  356. !
  357. receiver: anObject
  358. receiver := anObject
  359. !
  360. selector
  361. ^ message selector
  362. !
  363. selector: aString
  364. message selector: aString
  365. ! !
  366. !MessageSend methodsFor: 'evaluating'!
  367. value
  368. ^ message sendTo: self receiver
  369. !
  370. value: anObject
  371. ^ message
  372. arguments: { anObject };
  373. sendTo: self receiver
  374. !
  375. value: firstArgument value: secondArgument
  376. ^ message
  377. arguments: { firstArgument. secondArgument };
  378. sendTo: self receiver
  379. !
  380. value: firstArgument value: secondArgument value: thirdArgument
  381. ^ message
  382. arguments: { firstArgument. secondArgument. thirdArgument };
  383. sendTo: self receiver
  384. !
  385. valueWithPossibleArguments: aCollection
  386. self arguments: aCollection.
  387. ^ self value
  388. ! !
  389. !MessageSend methodsFor: 'initialization'!
  390. initialize
  391. super initialize.
  392. message := Message new
  393. ! !
  394. !MessageSend methodsFor: 'printing'!
  395. printOn: aStream
  396. super printOn: aStream.
  397. aStream
  398. nextPutAll: '(';
  399. nextPutAll: self receiver;
  400. nextPutAll: ' >> ';
  401. nextPutAll: self selector;
  402. nextPutAll: ')'
  403. ! !
  404. Object subclass: #MethodContext
  405. instanceVariableNames: ''
  406. package: 'Kernel-Methods'!
  407. !MethodContext commentStamp!
  408. I hold all the dynamic state associated with the execution of either a method activation resulting from a message send. I am used to build the call stack while debugging.
  409. My instances are JavaScript `SmalltalkMethodContext` objects defined in `boot.js`.!
  410. !MethodContext methodsFor: 'accessing'!
  411. basicReceiver
  412. <return self.receiver>
  413. !
  414. evaluatedSelector
  415. <return self.evaluatedSelector>
  416. !
  417. findContextSuchThat: testBlock
  418. "Search self and my sender chain for first one that satisfies `testBlock`.
  419. Answer `nil` if none satisfy"
  420. | context |
  421. context := self.
  422. [ context isNil] whileFalse: [
  423. (testBlock value: context)
  424. ifTrue: [ ^ context ].
  425. context := context outerContext ].
  426. ^ nil
  427. !
  428. home
  429. <return self.homeContext>
  430. !
  431. index
  432. <return self.index || 0>
  433. !
  434. locals
  435. <return self.locals || {}>
  436. !
  437. method
  438. | method lookupClass receiverClass supercall |
  439. self methodContext ifNil: [ ^ nil ].
  440. receiverClass := self methodContext receiver class.
  441. method := receiverClass lookupSelector: self methodContext selector.
  442. supercall := self outerContext
  443. ifNil: [ false ]
  444. ifNotNil: [ :outer | outer supercall ].
  445. ^ supercall
  446. ifFalse: [ method ]
  447. ifTrue: [ method methodClass superclass lookupSelector: self methodContext selector ]
  448. !
  449. methodContext
  450. self isBlockContext ifFalse: [ ^ self ].
  451. ^ self outerContext ifNotNil: [ :outer |
  452. outer methodContext ]
  453. !
  454. outerContext
  455. <return self.outerContext || self.homeContext>
  456. !
  457. receiver
  458. ^ (self isBlockContext and: [ self outerContext notNil ])
  459. ifTrue: [ self outerContext receiver ]
  460. ifFalse: [ self basicReceiver ]
  461. !
  462. selector
  463. <
  464. if(self.selector) {
  465. return $core.js2st(self.selector);
  466. } else {
  467. return nil;
  468. }
  469. >
  470. !
  471. sendIndexAt: aSelector
  472. <return self.sendIdx[aSelector] || 0>
  473. !
  474. sendIndexes
  475. <return self.sendIdx>
  476. !
  477. supercall
  478. <return self.supercall == true>
  479. ! !
  480. !MethodContext methodsFor: 'converting'!
  481. asString
  482. ^ self isBlockContext
  483. ifTrue: [ 'a block (in ', self methodContext asString, ')' ]
  484. ifFalse: [
  485. | methodClass |
  486. methodClass := self method methodClass.
  487. methodClass = self receiver class
  488. ifTrue: [ self receiver class name, ' >> ', self selector ]
  489. ifFalse: [ self receiver class name, '(', methodClass name, ') >> ', self selector ] ]
  490. ! !
  491. !MethodContext methodsFor: 'printing'!
  492. printOn: aStream
  493. super printOn: aStream.
  494. aStream
  495. nextPutAll: '(';
  496. nextPutAll: self asString;
  497. nextPutAll: ')'
  498. ! !
  499. !MethodContext methodsFor: 'testing'!
  500. isBlockContext
  501. "Block context do not have selectors."
  502. ^ self selector isNil
  503. ! !
  504. Object subclass: #NativeFunction
  505. instanceVariableNames: ''
  506. package: 'Kernel-Methods'!
  507. !NativeFunction commentStamp!
  508. I am a wrapper around native functions, such as `WebSocket`.
  509. For 'normal' functions (whose constructor is the JavaScript `Function` object), use `BlockClosure`.
  510. ## API
  511. See the class-side `instance creation` methods for instance creation.
  512. Created instances will most probably be instance of `JSObjectProxy`.
  513. ## Usage example:
  514. | ws |
  515. ws := NativeFunction constructor: 'WebSocket' value: 'ws://localhost'.
  516. ws at: 'onopen' put: [ ws send: 'hey there from Amber' ]!
  517. !NativeFunction class methodsFor: 'function calling'!
  518. functionNamed: aString
  519. <
  520. var nativeFunc=(new Function('return this'))()[aString];
  521. return nativeFunc();
  522. >
  523. !
  524. functionNamed: aString value: anObject
  525. <
  526. var nativeFunc=(new Function('return this'))()[aString];
  527. return nativeFunc(anObject);
  528. >
  529. !
  530. functionNamed: aString value: anObject value: anObject2
  531. <
  532. var nativeFunc=(new Function('return this'))()[aString];
  533. return nativeFunc(anObject,anObject2);
  534. >
  535. !
  536. functionNamed: aString value: anObject value: anObject2 value: anObject3
  537. <
  538. var nativeFunc=(new Function('return this'))()[aString];
  539. return nativeFunc(anObject,anObject2, anObject3);
  540. >
  541. !
  542. functionNamed: aString valueWithArgs: args
  543. <
  544. var nativeFunc=(new Function('return this'))()[aString];
  545. return Function.prototype.apply.call(nativeFunc, null, args);
  546. >
  547. !
  548. functionOf: nativeFunc
  549. <
  550. return nativeFunc();
  551. >
  552. !
  553. functionOf: nativeFunc value: anObject
  554. <
  555. return nativeFunc(anObject);
  556. >
  557. !
  558. functionOf: nativeFunc value: anObject value: anObject2
  559. <
  560. return nativeFunc(anObject,anObject2);
  561. >
  562. !
  563. functionOf: nativeFunc value: anObject value: anObject2 value: anObject3
  564. <
  565. return nativeFunc(anObject,anObject2, anObject3);
  566. >
  567. !
  568. functionOf: nativeFunc valueWithArgs: args
  569. <
  570. return Function.prototype.apply.call(nativeFunc, null, args);
  571. >
  572. ! !
  573. !NativeFunction class methodsFor: 'instance creation'!
  574. constructor: aString
  575. <
  576. self._deprecatedAPI_("Use constructorNamed:");
  577. var nativeFunc=eval(aString);
  578. return new nativeFunc();
  579. >
  580. !
  581. constructor: aString value:anObject
  582. <
  583. self._deprecatedAPI_("Use constructorNamed:value:");
  584. var nativeFunc=eval(aString);
  585. return new nativeFunc(anObject);
  586. >
  587. !
  588. constructor: aString value:anObject value: anObject2
  589. <
  590. self._deprecatedAPI_("Use constructorNamed:value:value:");
  591. var nativeFunc=eval(aString);
  592. return new nativeFunc(anObject,anObject2);
  593. >
  594. !
  595. constructor: aString value:anObject value: anObject2 value:anObject3
  596. <
  597. self._deprecatedAPI_("Use constructorNamed:value:value:value");
  598. var nativeFunc=eval(aString);
  599. return new nativeFunc(anObject,anObject2, anObject3);
  600. >
  601. !
  602. constructorNamed: aString
  603. <
  604. var nativeFunc=(new Function('return this'))()[aString];
  605. return new nativeFunc();
  606. >
  607. !
  608. constructorNamed: aString value: anObject
  609. <
  610. var nativeFunc=(new Function('return this'))()[aString];
  611. return new nativeFunc(anObject);
  612. >
  613. !
  614. constructorNamed: aString value: anObject value: anObject2
  615. <
  616. var nativeFunc=(new Function('return this'))()[aString];
  617. return new nativeFunc(anObject,anObject2);
  618. >
  619. !
  620. constructorNamed: aString value: anObject value: anObject2 value: anObject3
  621. <
  622. var nativeFunc=(new Function('return this'))()[aString];
  623. return new nativeFunc(anObject,anObject2, anObject3);
  624. >
  625. !
  626. constructorOf: nativeFunc
  627. <
  628. return new nativeFunc();
  629. >
  630. !
  631. constructorOf: nativeFunc value: anObject
  632. <
  633. return new nativeFunc(anObject);
  634. >
  635. !
  636. constructorOf: nativeFunc value: anObject value: anObject2
  637. <
  638. return new nativeFunc(anObject,anObject2);
  639. >
  640. !
  641. constructorOf: nativeFunc value: anObject value: anObject2 value: anObject3
  642. <
  643. return new nativeFunc(anObject,anObject2, anObject3);
  644. >
  645. ! !
  646. !NativeFunction class methodsFor: 'method calling'!
  647. methodOf: nativeFunc this: thisObject
  648. <
  649. return Function.prototype.call.call(nativeFunc, thisObject);
  650. >
  651. !
  652. methodOf: nativeFunc this: thisObject value: anObject
  653. <
  654. return Function.prototype.call.call(nativeFunc, thisObject, anObject);
  655. >
  656. !
  657. methodOf: nativeFunc this: thisObject value: anObject value: anObject2
  658. <
  659. return Function.prototype.call.call(nativeFunc, thisObject,anObject,anObject2);
  660. >
  661. !
  662. methodOf: nativeFunc this: thisObject value: anObject value: anObject2 value: anObject3
  663. <
  664. return Function.prototype.call.call(nativeFunc, thisObject,anObject,anObject2, anObject3);
  665. >
  666. !
  667. methodOf: nativeFunc this: thisObject valueWithArgs: args
  668. <
  669. return Function.prototype.apply.call(nativeFunc, thisObject, args);
  670. >
  671. ! !
  672. !NativeFunction class methodsFor: 'testing'!
  673. exists: aString
  674. ^ PlatformInterface existsGlobal: aString
  675. ! !
  676. Object subclass: #Timeout
  677. instanceVariableNames: 'rawTimeout'
  678. package: 'Kernel-Methods'!
  679. !Timeout commentStamp!
  680. I am wrapping the returns from `set{Timeout,Interval}`.
  681. ## Motivation
  682. Number suffices in browsers, but node.js returns an object.!
  683. !Timeout methodsFor: 'accessing'!
  684. rawTimeout: anObject
  685. rawTimeout := anObject
  686. ! !
  687. !Timeout methodsFor: 'timeout/interval'!
  688. clearInterval
  689. <
  690. var interval = self["@rawTimeout"];
  691. clearInterval(interval);
  692. >
  693. !
  694. clearTimeout
  695. <
  696. var timeout = self["@rawTimeout"];
  697. clearTimeout(timeout);
  698. >
  699. ! !
  700. !Timeout class methodsFor: 'instance creation'!
  701. on: anObject
  702. ^ self new rawTimeout: anObject; yourself
  703. ! !