File tree Expand file tree Collapse file tree 5 files changed +26
-5
lines changed Expand file tree Collapse file tree 5 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 6
6
(defun reset ()
7
7
(setf *env* (create-env *printlib* )))
8
8
9
+ (defvar *enable-Function.caller* nil
10
+ " If T, enables support for arguments.callee.caller/Function.caller property in newly compiled JavaScript code" )
11
+
9
12
(defun run-js (str &key (compile t ) (wrap-parse-errors nil ) (optimize nil ) (wrap-as-module nil ))
10
13
(unless (boundp ' *env*) (reset))
11
14
(let* ((ast (handler-bind ((js-parse-error
56
59
(format t (if continue " " " > " ))))))
57
60
58
61
(defun tests ()
59
- (with-js-env (*printlib* )
60
- (run-js-file (asdf :system-relative-pathname :cl-js " test.js" ))))
62
+ (let ((*enable-function.caller* t ))
63
+ (with-js-env (*printlib* )
64
+ (run-js-file (asdf :system-relative-pathname :cl-js " test.js" )))))
61
65
62
66
(defun js-obj (&optional proto struct-type)
63
67
(let ((cls (etypecase proto
Original file line number Diff line number Diff line change 2
2
(:use :cl :parse-js )
3
3
(:export # :run-js-file # :run-js # :js-repl
4
4
# :*env* # :with-js-env # :create-env # :add-to-env
5
+ # :*enable-Function.caller*
5
6
6
7
# :*printlib* # :requirelib
7
8
Original file line number Diff line number Diff line change 172
172
(.func " decodeURIComponent" (str)
173
173
(with-uri-err (url-encode :url-decode (to-string str) " " )))))
174
174
175
+ (defvar *Function.caller-stack* ' (:null :null ))
176
+
175
177
(add-to-lib *stdlib*
176
178
(flet ((defprops (obj props)
177
179
(let ((props (to-object props)))
251
253
(build-func (lambda (this &rest args-inner)
252
254
(declare (ignore this))
253
255
(apply proc self (append args args-inner)))
254
- (max 0 (- arity (length args)))))))))
256
+ (max 0 (- arity (length args))))))
257
+ (.active-r " caller" (second *Function.caller-stack* )))))
255
258
256
259
(add-to-lib *stdlib*
257
260
(.constructor " Array" (&rest args)
Original file line number Diff line number Diff line change @@ -541,6 +541,14 @@ function test_39() {
541
541
true ) ;
542
542
}
543
543
544
+ function test_40 ( ) {
545
+ var foo = function foo ( ) { return arguments . callee . caller ; } ;
546
+ var bar = function bar ( ) { return foo ( ) ; } ;
547
+ if ( typeof bar ( ) != "function" ) {
548
+ throw "arguments.callee.caller doesn't work" ;
549
+ }
550
+ }
551
+
544
552
function runTests ( ) {
545
553
var failures = [ ] ;
546
554
var run = 0 ;
Original file line number Diff line number Diff line change 410
410
(uses-args (or uses-eval (references-arguments body)))
411
411
(eval-scope (gensym " eval-scope" ))
412
412
(base-locals (cons " this" args))
413
- (fname (and uses-args (or name (symbol-name (gensym ))))))
413
+ (fname (and (or uses-args *enable-Function.caller* )
414
+ (or name (symbol-name (gensym ))))))
414
415
(when name (push name base-locals))
415
416
(when uses-args (push " arguments" base-locals))
416
417
(multiple-value-bind (locals internal) (find-locals body base-locals)
420
421
(make-simple-scope :vars locals))
421
422
(when uses-eval
422
423
(push (make-with-scope :var eval-scope) *scope* ))
423
- (let ((body1 ` ((let* (,@ (loop :for var :in internal :collect ` (, var :undefined ))
424
+ (let ((body1 ` ((let* (,@ (when *enable-Function.caller*
425
+ ` ((*Function.caller-stack*
426
+ (cons , (as-sym fname)
427
+ *Function.caller-stack* ))))
428
+ ,@ (loop :for var :in internal :collect ` (, var :undefined ))
424
429
; ; TODO sane object init
425
430
,@ (and uses-eval ` ((, eval-scope (make-obj (find-cls :object )))
426
431
(eval-env , (capture-scope)))))
You can’t perform that action at this time.
0 commit comments