Lines Matching refs:code
35 @item Small and easily embeddable: just a few C files, no external dependency, 210 KiB of x86 code …
66 Edit the top of the @code{Makefile} if you wish to select specific
67 options then run @code{make}.
69 You can type @code{make install} as root if you wish to install the binaries and support files to
70 @code{/usr/local} (this is not necessary to use QuickJS).
74 @code{qjs} is the command line interpreter (Read-Eval-Print Loop). You can pass
81 @code{qjsc} is the command line compiler:
88 generates a @code{hello} executable with no external dependency.
92 @subsection @code{qjs} interpreter
99 @table @code
104 @item -e @code{EXPR}
105 @item --eval @code{EXPR}
115 the filename extension is @code{.mjs} or if the first keyword of the
116 source is @code{import}.
123 the @code{"use bigint"} and @code{"use math"} directives.
133 @table @code
135 Make the @code{std} and @code{os} modules available to the loaded
148 @subsection @code{qjsc} compiler
155 @table @code
159 Output @code{main()} and bytecode in a C file. The default is to output an
171 Add initialization code for an external C module. See the
172 @code{c_module} example.
180 when the @code{-fno-x} options are used.
187 the @code{"use bigint"} and @code{"use math"} directives.
191 @section @code{qjscalc} application
193 The @code{qjscalc} application is a superset of the @code{qjs}
196 complex numbers, polynomials and matrices. The source code is in
202 Run @code{make test} to run the few built-in tests included in the
217 The patch adds the implementation specific @code{harness} functions
227 The configuration files @code{test262.conf}
228 (resp. @code{test262o.conf} for the old ES5.1 tests@footnote{The old
229 ES5.1 tests can be extracted with @code{git clone --single-branch
234 The file @code{test262_errors.txt} contains the current list of
236 an existing error is corrected or modified. Use the @code{-u} option
237 to update the current list of errors (or @code{make test2-update}).
239 The file @code{test262_report.txt} contains the logs of all the
244 Use the syntax @code{./run-test262 -c test262.conf -f filename.js} to
245 run a single test. Use the syntax @code{./run-test262 -c test262.conf
246 N} to start testing at test number @code{N}.
248 For more information, run @code{./run-test262} to see the command line
251 @code{run-test262} accepts the @code{-N} option to be invoked from
252 @code{test262-harness}@footnote{@url{https://github.com/bterlson/test262-harness}}
253 thru @code{eshost}. Unless you want to compare QuickJS with other
283 …e @code{"use strip"} indicates that the debug information (including the source code of the functi…
285 @item The first line of a script beginning with @code{#!} is ignored.
292 standard Javascript. See @code{jsbignum.pdf} for more information.
296 @item @code{BigDecimal} support: arbitrary large floating point numbers in base 10.
298 @item @code{BigFloat} support: arbitrary large floating point numbers in base 2.
302 @item The directive @code{"use bigint"} enables the bigint mode where integers are @code{BigInt} by…
304 …code{"use math"} enables the math mode where the division and power operators on integers produce …
315 @item Module names with a leading @code{.} or @code{..} are relative
318 @item Module names without a leading @code{.} or @code{..} are system
319 modules, such as @code{std} or @code{os}.
321 @item Module names ending with @code{.so} are native modules using the
329 interpreter. It contains the two modules @code{std} and @code{os} and
334 @table @code
344 @subsection @code{std} module
346 The @code{std} module provides wrappers to the libc @file{stdlib.h}
351 @table @code
357 Evaluate the string @code{str} as a script (global
358 eval). @code{options} is an optional object containing the following
361 @table @code
368 Evaluate the file @code{filename} as a script (global eval).
371 Load the file @code{filename} and return it as a string assuming UTF-8
372 encoding. Return @code{null} in case of I/O error.
375 Open a file (wrapper to the libc @code{fopen()}). Return the FILE
376 object or @code{null} in case of I/O error. If @code{errorObj} is not
377 undefined, set its @code{errno} property to the error code or to 0 if
382 @code{popen()}). Return the FILE
383 object or @code{null} in case of I/O error. If @code{errorObj} is not
384 undefined, set its @code{errno} property to the error code or to 0 if
389 @code{fdopen()}). Return the FILE
390 object or @code{null} in case of I/O error. If @code{errorObj} is not
391 undefined, set its @code{errno} property to the error code or to 0 if
396 object or @code{null} in case of I/O error. If @code{errorObj} is not
397 undefined, set its @code{errno} property to the error code or to 0 if
401 Equivalent to @code{std.out.puts(str)}.
404 Equivalent to @code{std.out.printf(fmt, ...args)}.
412 Wrappers to the libc file @code{stdin}, @code{stdout}, @code{stderr}.
424 @table @code
438 Return a string that describes the error @code{errno}.
446 Return the value of the environment variable @code{name} or
447 @code{undefined} if it is not defined.
451 Download @code{url} using the @file{curl} command line
452 utility. @code{options} is an optional object containing the following
455 @table @code
464 the properties @code{response} (response content),
465 @code{responseHeaders} (headers separated by CRLF), @code{status}
466 (status code). @code{response} is @code{null} is case of protocol or
467 network error. If @code{full} is false, only the response is
468 returned if the status is between 200 and 299. Otherwise @code{null}
475 Parse @code{str} using a superset of @code{JSON.parse}. The
483 @item @code{\f} and @code{\v} are accepted as space characters
485 @item octal (@code{0o} prefix) and hexadecimal (@code{0x} prefix) numbers
491 @table @code
493 Close the file. Return 0 if OK or @code{-errno} in case of I/O error.
499 The same formats as the standard C library @code{printf} are
500 supported. Integer format types (e.g. @code{%d}) truncate the Numbers
501 or BigInts to 32 bits. Use the @code{l} modifier (e.g. @code{%ld}) to
508 @code{std.SEEK_*}). @code{offset} can be a number or a bigint. Return
509 0 if OK or @code{-errno} in case of I/O error.
524 Read @code{length} bytes from the file to the ArrayBuffer @code{buffer} at byte
525 position @code{position} (wrapper to the libc @code{fread}).
528 Write @code{length} bytes to the file from the ArrayBuffer @code{buffer} at byte
529 position @code{position} (wrapper to the libc @code{fread}).
536 Read @code{max_size} bytes from the file and return them as a string
537 assuming UTF-8 encoding. If @code{max_size} is not present, the file
547 @subsection @code{os} module
549 The @code{os} module provides Operating System specific functions:
560 error code.
564 @table @code
581 Close the file handle @code{fd}.
584 Seek in the file. Use @code{std.SEEK_*} for
585 @code{whence}. @code{offset} is either a number or a bigint. If
586 @code{offset} is a bigint, a bigint is returned too.
589 Read @code{length} bytes from the file handle @code{fd} to the
590 ArrayBuffer @code{buffer} at byte position @code{offset}.
594 Write @code{length} bytes to the file handle @code{fd} from the
595 ArrayBuffer @code{buffer} at byte position @code{offset}.
599 Return @code{true} is @code{fd} is a TTY (terminal) handle.
602 Return the TTY size as @code{[width, height]} or @code{null} if not available.
608 Remove a file. Return 0 if OK or @code{-errno}.
611 Rename a file. Return 0 if OK or @code{-errno}.
614 Return @code{[str, err]} where @code{str} is the canonicalized absolute
615 pathname of @code{path} and @code{err} the error code.
618 Return @code{[str, err]} where @code{str} is the current working directory
619 and @code{err} the error code.
622 Change the current directory. Return 0 if OK or @code{-errno}.
625 Create a directory at @code{path}. Return 0 if OK or @code{-errno}.
630 Return @code{[obj, err]} where @code{obj} is an object containing the
631 file status of @code{path}. @code{err} is the error code. The
632 following fields are defined in @code{obj}: dev, ino, mode, nlink,
634 specified in milliseconds since 1970. @code{lstat()} is the same as
635 @code{stat()} excepts that it returns information about the link
648 Constants to interpret the @code{mode} property returned by
649 @code{stat()}. They have the same value as in the C system header
653 Change the access and modification times of the file @code{path}. The
654 times are specified in milliseconds since 1970. Return 0 if OK or @code{-errno}.
657 Create a link at @code{linkpath} containing the string @code{target}. Return 0 if OK or @code{-errn…
660 Return @code{[str, err]} where @code{str} is the link target and @code{err}
661 the error code.
664 Return @code{[array, err]} where @code{array} is an array of strings
665 containing the filenames of the directory @code{path}. @code{err} is
666 the error code.
669 Add a read handler to the file handle @code{fd}. @code{func} is called
670 each time there is data pending for @code{fd}. A single read handler
671 per file handle is supported. Use @code{func = null} to remove the
675 Add a write handler to the file handle @code{fd}. @code{func} is
676 called each time data can be written to @code{fd}. A single write
677 handler per file handle is supported. Use @code{func = null} to remove
681 Call the function @code{func} when the signal @code{signal}
683 @code{null} to set the default handler or @code{undefined} to ignore
695 Send the signal @code{sig} to the process @code{pid}.
698 Execute a process with the arguments @code{args}. @code{options} is an
701 @table @code
704 terminated. In this case, @code{exec} return the exit code if positive
710 @code{PATH} environment variable.
713 String (default = @code{args[0]}). Set the file to be executed.
729 Integer. If present, the process uid with @code{setuid}.
732 Integer. If present, the process gid with @code{setgid}.
737 @code{waitpid} Unix system call. Return the array @code{[ret,
738 status]}. @code{ret} contains @code{-errno} in case of error.
741 Constant for the @code{options} argument of @code{waitpid}.
744 @code{dup} Unix system call.
747 @code{dup2} Unix system call.
750 @code{pipe} Unix system call. Return two handles as @code{[read_fd,
754 Sleep during @code{delay_ms} milliseconds.
757 Call the function @code{func} after @code{delay} ms. Return a handle
764 Return a string representing the platform: @code{"linux"}, @code{"darwin"},
765 @code{"win32"} or @code{"js"}.
769 @code{WebWorkers}. @code{source} is a string containing the module
777 @table @code
779 In the created worker, @code{Worker.parent} represents the parent
785 @table @code
788 Send a message to the corresponding worker. @code{msg} is cloned in
789 the destination worker using an algorithm similar to the @code{HTML}
790 structured clone algorithm. @code{SharedArrayBuffer} are shared
793 Current limitations: @code{Map} and @code{Set} are not supported
800 argument. It is an object with a @code{data} property containing the
802 one non @code{null} @code{onmessage} handler.
811 defined in the header @code{quickjs.h}.
815 @code{JSRuntime} represents a Javascript runtime corresponding to an
820 @code{JSContext} represents a Javascript context (or Realm). Each
828 @code{JSValue} represents a Javascript value which can be a primitive
830 explicitly duplicate (@code{JS_DupValue()}, increment the reference
831 count) or free (@code{JS_FreeValue()}, decrement the reference count)
837 @code{JS_NewCFunction()}. @code{JS_SetPropertyFunctionList()} is a
843 general rule, C functions take constant @code{JSValue}s as parameters
845 @code{JSValue}.
850 must be explicitly tested and handled by the C code. The specific
851 @code{JSValue} @code{JS_EXCEPTION} indicates that an exception
853 @code{JSContext} and can be retrieved with @code{JS_GetException()}.
857 Use @code{JS_Eval()} to evaluate a script or module source.
859 If the script or module was compiled to bytecode with @code{qjsc}, it
860 can be evaluated by calling @code{js_std_eval_binary()}. The advantage
862 the compiler can be removed from the executable if no @code{eval} is
869 binary file in @code{qjsc}.
874 C opaque data is determined with the class ID (@code{JSClassID}) of
876 class (@code{JS_NewClassID()}, @code{JS_NewClass()}). Then you can
877 create objects of this class with @code{JS_NewObjectClass()} and get or
879 @code{JS_GetOpaque()}/@code{JS_SetOpaque()}.
882 which is called when the object is destroyed. A @code{gc_mark} method
888 JSClass are allocated per @code{JSRuntime}. @code{JS_SetClassProto()}
890 JSContext. @code{JS_NewObjectClass()} sets this prototype in the
904 Use @code{JS_SetMemoryLimit()} to set a global memory allocation limit
908 @code{JS_NewRuntime2()}.
910 The maximum system stack size can be set with @code{JS_SetMaxStackSize()}.
914 Use @code{JS_SetInterruptHandler()} to set a callback which is
915 regularly called by the engine when it is executing code. This
919 @code{Ctrl-C} handler.
930 compact code.
941 Direct @code{eval} in strict mode is optimized.
945 @subsection @code{qjsc} compiler
947 The @code{qjsc} compiler generates C sources from Javascript files. By
949 (@code{gcc} or @code{clang}).
953 contains a @code{main()} function with the necessary C code to initialize the
957 Javascript code can be mixed with C modules.
960 be disabled, in particular @code{eval} or the regular expressions. The
961 code removal relies on the Link Time Optimization of the system
966 @code{qjsc} works by compiling scripts or modules and then serializing
1014 collection roots need to be manipulated in the C code.
1024 In 64-bit code, JSValue are 128-bit large and no NaN boxing is used. The
1025 rationale is that in 64-bit code memory usage is less critical.
1049 The full regexp library weights about 15 KiB (x86 code), excluding the
1063 The full Unicode library weights about 45 KiB (x86 code).
1067 BigInt, BigFloat and BigDecimal are implemented with the @code{libbf}
1069 KiB (x86 code) and provides arbitrary precision IEEE 754 floating