Skip to content

Commit 56f506d

Browse files
committed
WIP
1 parent 239ad34 commit 56f506d

27 files changed

+193
-232
lines changed

doc/dev/manual/bindings.wiki

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
=== Global variables
66

77
Global JavaScript variables are properties of the global object. Use
8-
{{{Js.Unsafe.global}}} to access them ({{{window}}} in browsers,
8+
<<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.global>> to access them ({{{window}}} in browsers,
99
{{{globalThis}}} in Node.js):
1010

1111
<<code language="ocaml"|
@@ -17,18 +17,18 @@ let get_config () : config Js.t = Js.Unsafe.global##.myAppConfig
1717
let set_config (x : config Js.t) = Js.Unsafe.global##.myAppConfig := x
1818
>>
1919

20-
You can also use {{{Js.Unsafe.js_expr}}} for any JavaScript expression:
20+
You can also use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.js_expr>> for any JavaScript expression:
2121
<<code language="ocaml"|
2222
let v = (Js.Unsafe.js_expr "window")##.document
2323
>>
2424

25-
Be careful: both {{{Js.Unsafe.global}}} and {{{Js.Unsafe.js_expr}}} are untyped.
25+
Be careful: both <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.global>> and <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.js_expr>> are untyped.
2626
Verify the library documentation before writing type annotations.
2727

2828
=== Untyped property access
2929

3030
When a property is missing from the OCaml interface (e.g., dynamically added
31-
by a library), use {{{Js.Unsafe.coerce}}} for untyped access:
31+
by a library), use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.coerce>> for untyped access:
3232

3333
<<code language="ocaml"|
3434
(* Read a property *)
@@ -81,8 +81,8 @@ end
8181
OCaml method names are transformed to JavaScript names using underscore
8282
conventions. When accessing a field of an object, the name given in OCaml
8383
is transformed by:
84-
1. Removing a leading underscore (if present)
85-
2. Removing all characters starting from the last underscore
84+
# Removing a leading underscore (if present)
85+
# Removing all characters starting from the last underscore
8686
8787
This enables:
8888
- **Capitalized names**: Use {{{_Foo}}} to refer to JavaScript's {{{Foo}}}
@@ -155,8 +155,8 @@ these functions to convert between them.
155155

156156
=== Strings
157157

158-
OCaml strings and JavaScript strings have different encodings. Use {{{Js.string}}}
159-
and {{{Js.to_string}}} for UTF-8 encoded OCaml strings:
158+
OCaml strings and JavaScript strings have different encodings. Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.string>>
159+
and <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.to_string>> for UTF-8 encoded OCaml strings:
160160

161161
<<code language="ocaml"|
162162
(* OCaml string -> JS string *)
@@ -166,7 +166,7 @@ let js_str : Js.js_string Js.t = Js.string "Hello"
166166
let ocaml_str : string = Js.to_string js_str
167167
>>
168168

169-
For binary data (bytes 0-255), use {{{Js.bytestring}}} and {{{Js.to_bytestring}}}:
169+
For binary data (bytes 0-255), use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.bytestring>> and <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.to_bytestring>>:
170170

171171
<<code language="ocaml"|
172172
let js_bytes = Js.bytestring "\x00\x01\x02"
@@ -175,7 +175,7 @@ let ocaml_bytes = Js.to_bytestring js_bytes
175175

176176
=== Booleans
177177

178-
JavaScript booleans are not OCaml booleans. Use {{{Js.bool}}} and {{{Js.to_bool}}}:
178+
JavaScript booleans are not OCaml booleans. Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.bool>> and <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.to_bool>>:
179179

180180
<<code language="ocaml"|
181181
let js_true : bool Js.t = Js._true (* or Js.bool true *)
@@ -185,8 +185,8 @@ let ocaml_bool : bool = Js.to_bool js_true
185185

186186
=== Numbers
187187

188-
OCaml integers can be used directly. For floats, use {{{Js.float}}} and
189-
{{{Js.to_float}}}:
188+
OCaml integers can be used directly. For floats, use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.number_of_float>> and
189+
<<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.float_of_number>>:
190190

191191
<<code language="ocaml"|
192192
(* Integers work directly *)
@@ -222,9 +222,9 @@ let ocaml_arr : int array = Js.to_array js_arr
222222
JavaScript has two "missing value" types: {{{null}}} and {{{undefined}}}.
223223
Js_of_ocaml represents these with distinct types.
224224

225-
=== {{{Js.Opt}}} for nullable values ({{{null}}})
225+
=== <<a_api subproject="js_of_ocaml"|module Js_of_ocaml.Js.Opt>> for nullable values ({{{null}}})
226226

227-
Use {{{Js.Opt}}} for values that may be {{{null}}} (e.g., DOM methods that
227+
Use <<a_api subproject="js_of_ocaml"|module Js_of_ocaml.Js.Opt>> for values that may be {{{null}}} (e.g., DOM methods that
228228
return {{{null}}} when an element is not found):
229229

230230
<<code language="ocaml"|
@@ -247,9 +247,9 @@ let some_val : element Js.t Js.opt = Js.some element
247247
let null_val : element Js.t Js.opt = Js.null
248248
>>
249249

250-
=== {{{Js.Optdef}}} for optional values ({{{undefined}}})
250+
=== <<a_api subproject="js_of_ocaml"|module Js_of_ocaml.Js.Optdef>> for optional values ({{{undefined}}})
251251

252-
Use {{{Js.Optdef}}} for values that may be {{{undefined}}} (e.g., optional
252+
Use <<a_api subproject="js_of_ocaml"|module Js_of_ocaml.Js.Optdef>> for values that may be {{{undefined}}} (e.g., optional
253253
object properties, array access beyond bounds):
254254

255255
<<code language="ocaml"|
@@ -274,7 +274,7 @@ let undef_val : int Js.optdef = Js.undefined
274274
|= Scenario |= Type |= Example |
275275
| DOM lookup | {{{Js.Opt}}} | {{{getElementById}}} returns {{{null}}} if not found |
276276
| Optional property | {{{Js.Optdef}}} | Property may not exist on object |
277-
| Array access | {{{Js.Optdef}}} | {{{Js.array_get}}} returns {{{undefined}}} for missing index |
277+
| Array access | {{{Js.Optdef}}} | <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.array_get>> returns {{{undefined}}} for missing index |
278278
| API returns null | {{{Js.Opt}}} | Many DOM APIs use {{{null}}} for "no value" |
279279
| Feature detection | {{{Js.Optdef}}} | Check if method/property exists |
280280

@@ -300,7 +300,7 @@ should be bound.
300300

301301
=== Standalone functions with {{{fun_call}}}
302302

303-
Use {{{Js.Unsafe.fun_call}}} for functions where {{{this}}} doesn't matter:
303+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.fun_call>> for functions where {{{this}}} doesn't matter:
304304

305305
<<code language="ocaml"|
306306
(* Equivalent to: decodeURI(s) *)
@@ -318,7 +318,7 @@ let parseInt (s : Js.js_string Js.t) : int =
318318

319319
=== Methods with {{{meth_call}}}
320320

321-
Use {{{Js.Unsafe.meth_call}}} to call a method on an object ({{{this}}} is
321+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.meth_call>> to call a method on an object ({{{this}}} is
322322
bound to the object):
323323

324324
<<code language="ocaml"|
@@ -330,7 +330,7 @@ let slice arr start stop =
330330

331331
=== Functions with explicit {{{this}}} binding
332332

333-
Use {{{Js.Unsafe.call}}} when you need to explicitly set {{{this}}}:
333+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.call>> when you need to explicitly set {{{this}}}:
334334

335335
<<code language="ocaml"|
336336
(* Equivalent to: func.call(thisArg, arg1, arg2) *)
@@ -346,9 +346,9 @@ API for more details.
346346
When JavaScript code needs to call back into OCaml (e.g., event handlers,
347347
callbacks for async operations), you must wrap OCaml functions appropriately.
348348

349-
=== Basic callbacks with {{{Js.wrap_callback}}}
349+
=== Basic callbacks with <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.wrap_callback>>
350350

351-
Use {{{Js.wrap_callback}}} to wrap an OCaml function for JavaScript:
351+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.wrap_callback>> to wrap an OCaml function for JavaScript:
352352

353353
<<code language="ocaml"|
354354
(* setTimeout example *)
@@ -360,13 +360,13 @@ let set_timeout f ms =
360360
let () = set_timeout (fun () -> print_endline "Hello!") 1000.
361361
>>
362362

363-
{{{Js.wrap_callback}}} handles partial application correctly: if JavaScript
363+
<<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.wrap_callback>> handles partial application correctly: if JavaScript
364364
calls the function with fewer arguments than expected, the result is a
365365
partially applied function.
366366

367367
=== Callbacks with {{{this}}} binding
368368

369-
Use {{{Js.wrap_meth_callback}}} when the callback needs access to {{{this}}}:
369+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.wrap_meth_callback>> when the callback needs access to {{{this}}}:
370370

371371
<<code language="ocaml"|
372372
(* The first parameter receives the 'this' value *)
@@ -379,7 +379,7 @@ let callback = Js.wrap_meth_callback (fun this event ->
379379
=== Strict arity callbacks
380380

381381
For performance-critical code, or when you don't need partial application
382-
support, use {{{Js.Unsafe.callback}}} or {{{Js.Unsafe.callback_with_arity}}}:
382+
support, use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.callback>> or <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.callback_with_arity>>:
383383

384384
<<code language="ocaml"|
385385
(* Strict callback - missing args become undefined, extra args are lost *)
@@ -391,9 +391,9 @@ let arity_cb = Js.Unsafe.callback_with_arity 2 (fun x y -> x + y)
391391

392392
=== DOM event handlers
393393

394-
For DOM events, use {{{Dom.handler}}} or {{{Dom_html.handler}}} which
394+
For DOM events, use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Dom.handler>> or <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Dom_html.handler>> which
395395
automatically wraps the function and handles the return value (returning
396-
{{{Js._false}}} prevents the default action):
396+
<<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js._false>> prevents the default action):
397397

398398
<<code language="ocaml"|
399399
let button = Dom_html.getElementById "myButton"
@@ -405,7 +405,7 @@ let handler = Dom_html.handler (fun event ->
405405
button##.onclick := handler
406406
>>
407407

408-
For handlers that need access to {{{this}}}, use {{{Dom.full_handler}}}:
408+
For handlers that need access to {{{this}}}, use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Dom.full_handler>>:
409409

410410
<<code language="ocaml"|
411411
let handler = Dom.full_handler (fun this event ->
@@ -416,7 +416,7 @@ let handler = Dom.full_handler (fun this event ->
416416

417417
=== Callbacks with variable arguments
418418

419-
Use {{{Js.Unsafe.callback_with_arguments}}} when the callback receives a
419+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.callback_with_arguments>> when the callback receives a
420420
variable number of arguments:
421421

422422
<<code language="ocaml"|
@@ -480,7 +480,7 @@ new%js someClass arg1 arg2
480480

481481
To construct a JS object without calling a constructor, use the
482482
<<a_manual chapter="Ppx"|Ppx>> syntax extension (recommended) or
483-
{{{Js.Unsafe.obj}}}.
483+
<<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.obj>>.
484484

485485
=== Using the PPX syntax (recommended)
486486

@@ -499,9 +499,9 @@ This produces the equivalent of:
499499

500500
See the <<a_manual chapter="Ppx"|Ppx documentation>> for more details.
501501

502-
=== Using {{{Js.Unsafe.obj}}}
502+
=== Using <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.obj>>
503503

504-
For dynamic object construction, use {{{Js.Unsafe.obj}}} with an array of
504+
For dynamic object construction, use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.obj>> with an array of
505505
key-value pairs:
506506

507507
<<code language="ocaml"|
@@ -534,7 +534,7 @@ let call_with_options () =
534534

535535
JavaScript APIs vary across browsers and environments. A method or property
536536
may exist in one browser but not another, or may have been added in a recent
537-
version. Use {{{Js.Optdef}}} to safely check for and access optional members.
537+
version. Use <<a_api subproject="js_of_ocaml"|module Js_of_ocaml.Js.Optdef>> to safely check for and access optional members.
538538

539539
=== Checking if a member exists
540540

@@ -545,7 +545,7 @@ let has_prop obj = Js.Optdef.test (Js.Unsafe.coerce obj)##.someProp
545545

546546
=== Safely accessing optional members
547547

548-
Use {{{Js.Optdef.to_option}}} to convert to an OCaml option:
548+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Optdef.to_option>> to convert to an OCaml option:
549549

550550
<<code language="ocaml"|
551551
let get_optional_method obj =
@@ -557,7 +557,7 @@ let () =
557557
| None -> (* fallback behavior *)
558558
>>
559559

560-
Use {{{Js.Optdef.case}}} for inline handling:
560+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Optdef.case>> for inline handling:
561561

562562
<<code language="ocaml"|
563563
let result =
@@ -584,7 +584,7 @@ requires a single type, use an opaque type with runtime type checking.
584584

585585
=== Using {{{instanceof}}} for object types
586586

587-
Use {{{Js.instanceof}}} to distinguish between different object types
587+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.instanceof>> to distinguish between different object types
588588
(e.g., DOM nodes, custom classes). Define an opaque type and cast functions:
589589

590590
<<code language="ocaml"|
@@ -619,7 +619,7 @@ let handle_child (container : container Js.t) =
619619

620620
=== Using {{{typeof}}} for primitive types
621621

622-
For primitive types (string, number, boolean), use {{{Js.typeof}}}:
622+
For primitive types (string, number, boolean), use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.typeof>>:
623623

624624
<<code language="ocaml"|
625625
type string_or_number
@@ -658,7 +658,7 @@ let handle container =
658658

659659
== Accessing JavaScript runtime values
660660

661-
The {{{Jsoo_runtime.Js.runtime_value}}} function allows direct access to JavaScript
661+
The <<a_api subproject="js_of_ocaml"|val Jsoo_runtime.Js.runtime_value>> function allows direct access to JavaScript
662662
values provided by the runtime (declared with {{{//Provides:}}} directives in
663663
JavaScript files).
664664

doc/dev/manual/build-toplevel.wiki

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
= Building a toplevel
22

3-
First, initialize the toplevel using {{{Js_of_ocaml_toplevel.JsooTop.initialize}}}.
3+
First, initialize the toplevel using <<a_api subproject="js_of_ocaml-toplevel"|val Js_of_ocaml_toplevel.JsooTop.initialize>>.
44

55
Then, build your bytecode program with debug enabled ({{{-g}}}) and linkall ({{{-linkall}}}). Link in all the libraries you want accessible in the final toplevel.
66

@@ -18,9 +18,9 @@ jsoo_listunits -o units.txt stdlib str
1818

1919
OCaml supports dynlink of bytecode files using the {{{dynlink}}} library. To use it when compiled to JavaScript:
2020

21-
1. Link {{{js_of_ocaml-compiler.dynlink}}} to initialize dynlink support (initialization is automatic via side-effect)
22-
2. Build your bytecode program with debug enabled ({{{-g}}}) and linkall ({{{-linkall}}})
23-
3. Compile your program to JavaScript passing the {{{--dynlink}}} flag
21+
# Link {{{js_of_ocaml-compiler.dynlink}}} to initialize dynlink support (initialization is automatic via side-effect)
22+
# Build your bytecode program with debug enabled ({{{-g}}}) and linkall ({{{-linkall}}})
23+
# Compile your program to JavaScript passing the {{{--dynlink}}} flag
2424
2525
== Example
2626

doc/dev/manual/contribute.wiki

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44

55
If you encounter a problem when using js_of_ocaml or if you have any questions, please open a [[https://github.com/ocsigen/js_of_ocaml/issues/|GitHub issue]].
66

7-
1. Check first if your issue has already been [[https://github.com/ocsigen/js_of_ocaml/issues/|reported]].
8-
2. Include the version of ocaml and js_of_ocaml you are using ({{{ocamlc -version}}}, {{{js_of_ocaml --version}}}).
9-
3. Describe the expected and actual behavior.
10-
4. Do not unsubscribe from the issue until it is closed, the maintainers may ask for your feedback.
7+
# Check first if your issue has already been [[https://github.com/ocsigen/js_of_ocaml/issues/|reported]].
8+
# Include the version of ocaml and js_of_ocaml you are using ({{{ocamlc -version}}}, {{{js_of_ocaml --version}}}).
9+
# Describe the expected and actual behavior.
10+
# Do not unsubscribe from the issue until it is closed, the maintainers may ask for your feedback.
1111
1212
== Pull Requests
1313

1414
We actively welcome pull requests.
1515

16-
1. Prior to investing a large amount of time into significant or invasive changes, it is likely more efficient to first open an issue for discussion and planning.
17-
2. Install all dependencies (see Install dependencies)
18-
3. Fork the repository and create your branch from {{{master}}}.
19-
4. If you have added code that should be tested, add tests.
20-
5. Ensure tests still pass (see Running the tests).
16+
# Prior to investing a large amount of time into significant or invasive changes, it is likely more efficient to first open an issue for discussion and planning.
17+
# Install all dependencies (see Install dependencies)
18+
# Fork the repository and create your branch from {{{master}}}.
19+
# If you have added code that should be tested, add tests.
20+
# Ensure tests still pass (see Running the tests).
2121
2222

2323
=== Install dependencies

doc/dev/manual/debug.wiki

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ See https://developer.chrome.com/docs/devtools/javascript for details.
5353

5454
=== Programmatic breakpoints
5555

56-
Insert breakpoints in your OCaml code:
56+
Insert breakpoints in your OCaml code using <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.debugger>>:
5757

5858
<<code language="ocaml"|
5959
let my_function x =
@@ -81,10 +81,10 @@ Debugger listening on ws://127.0.0.1:9229/...
8181

8282
=== Chrome DevTools for Node.js
8383

84-
1. Run {{{node --inspect}}} or {{{node --inspect-brk}}} (breaks on first line)
85-
2. Open Chrome and navigate to {{{chrome://inspect}}}
86-
3. Click "Open dedicated DevTools for Node"
87-
4. Your program appears in the Sources panel
84+
# Run {{{node --inspect}}} or {{{node --inspect-brk}}} (breaks on first line)
85+
# Open Chrome and navigate to {{{chrome://inspect}}}
86+
# Click "Open dedicated DevTools for Node"
87+
# Your program appears in the Sources panel
8888
8989
== Stack traces
9090

doc/dev/manual/effects.wiki

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ CPS version. The choice of running the CPS version is delayed to run time.
1919

2020
Since CPS code is usually slower, this can avoid performance degradations. You can
2121
also ensure that some code runs in direct style using
22-
{{{Jsoo_runtime.Effect.assume_no_perform}}}.
22+
<<a_api subproject="js_of_ocaml"|val Jsoo_runtime.Effect.assume_no_perform>>.
2323

2424
== Dune integration
2525

@@ -47,26 +47,15 @@ This setup supports both separate and whole program compilation.
4747

4848
=== Per-executable setup
4949

50-
To enable effect handlers for specific binaries only, you need to use whole
51-
program compilation:
50+
To enable effect handlers for specific executables:
5251

5352
{{{
5453
(executable
5554
(name main)
5655
(js_of_ocaml
57-
(compilation_mode whole_program)
5856
(flags (:standard --effects=double-translation))))
5957
}}}
6058

61-
Using separate compilation with effects enabled only for some executables will
62-
result in a linking error:
63-
64-
{{{
65-
js_of_ocaml: Error: Incompatible build info detected while linking.
66-
- test6.bc.runtime.js: effects=disabled
67-
- .cmphash.eobjs/byte/dune__exe.cmo.js: effects=double-translation
68-
}}}
69-
7059
== See also
7160

7261
* <<a_manual chapter="options"|Command line options>> - Full list of {{{--effects}}} modes

0 commit comments

Comments
 (0)