Skip to content

Commit f9d8435

Browse files
committed
Improvements to docs
1 parent 93b99d9 commit f9d8435

File tree

3 files changed

+59
-42
lines changed

3 files changed

+59
-42
lines changed

compiler/prelude/jsmapping.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ var $internalize = function(v, t, recv) {
206206
if (v.constructor !== Boolean) {
207207
$throwRuntimeError("tried to internalize non-bool value of type " + $typeof(v));
208208
}
209-
return Boolean(v);
209+
return Boolean(v);
210210
case $kindInt:
211211
return parseInt(v);
212212
case $kindInt8:
@@ -383,31 +383,31 @@ var $internalize = function(v, t, recv) {
383383
};
384384
385385
var $typeof = function(v) {
386-
if (v === undefined) {
387-
return "undefined";
388-
}
386+
if (v === undefined) {
387+
return "undefined";
388+
}
389389
390-
if (v === null) {
391-
return "null";
392-
}
390+
if (v === null) {
391+
return "null";
392+
}
393393
394-
var to = typeof v;
394+
var to = typeof v;
395395
396-
switch (to) {
397-
case "boolean":
398-
return to;
399-
case "number":
400-
return to;
401-
case "string":
402-
return to;
403-
case "symbol":
404-
return to;
405-
case "function":
406-
return to;
407-
default:
408-
return v.constructor.name;
409-
}
410-
}
396+
switch (to) {
397+
case "boolean":
398+
return to;
399+
case "number":
400+
return to;
401+
case "string":
402+
return to;
403+
case "symbol":
404+
return to;
405+
case "function":
406+
return to;
407+
default:
408+
return v.constructor.name;
409+
}
410+
};
411411
412412
/* $isASCII reports whether string s contains only ASCII characters. */
413413
var $isASCII = function(s) {

js/js.go

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,52 @@
99
// When values pass from Javascript to Go, a process known as internalization,
1010
// the following conversion table is applied:
1111
//
12-
// |----------------+-------------------------+---------------+--------|
13-
// | Go target type | Javascript source value | Translation | Result |
14-
// |----------------+-------------------------+---------------+--------|
15-
// | string | null | UTF16 -> UTF8 | "" |
16-
// | | undefined | | "" |
17-
// | | "" | | "" |
18-
// | | new String("") | | "" |
19-
// | | "ok" † | | "ok" |
20-
// | | new String("ok") † | | "ok" |
21-
// |----------------+-------------------------+---------------+--------|
22-
// | bool | null | none | false |
23-
// | | undefined | | false |
24-
// | | false † | | false |
25-
// | | new Boolean(false) † | | false |
26-
// |----------------+-------------------------+---------------+--------|
12+
// |----------------+---------------+-------------------------+--------|
13+
// | Go target type | Translation | Javascript source value | Result |
14+
// |----------------+---------------+-------------------------+--------|
15+
// | string | UTF16 -> UTF8 | null | "" |
16+
// | | | undefined | "" |
17+
// | | | "" | "" |
18+
// | | | new String("") | "" |
19+
// | | | "ok" † | "ok" |
20+
// | | | new String("ok") † | "ok" |
21+
// |----------------+---------------+-------------------------+--------|
22+
// | bool | none | null | false |
23+
// | | | undefined | false |
24+
// | | | false † | false |
25+
// | | | new Boolean(false) † | false |
26+
// |----------------+---------------+-------------------------+--------|
2727
//
2828
// Any source values not listed in this table cause a runtime panic for a given
2929
// target type if a conversion is attempted, e.g. a Javascript number value
3030
// being assigned to a string type Go variable.
3131
//
3232
// Source values annotated with † are generally applicable to all valid
3333
// values of the target type. e.g. for target type string, "ok" represents
34-
// all valid string values.
34+
// all valid string primitive values.
3535
//
3636
// Externalization
3737
//
3838
// When values pass from Go to Javascript, a process known as externalization,
3939
// the following conversion table is applied:
4040
//
41-
// To follow
41+
// |----------------+---------------+-----------------+--------+---------+-------------|
42+
// | Go source type | Translation | Go source value | Result | typeof | constructor |
43+
// |----------------+---------------+-----------------+--------+---------+-------------|
44+
// | string | UTF8 -> UTF16 | "" | "" | string | String |
45+
// | | | "ok" † | "ok" | | |
46+
// |----------------+---------------+-----------------+--------+---------+-------------|
47+
// | bool | none | false | false | boolean | Boolean |
48+
// | | | true | true | | |
49+
// |----------------+---------------+-----------------+--------+---------+-------------|
50+
//
51+
// Source values annotated with † are generally applicable to all valid
52+
// values of the target type. e.g. for target type string, "ok" represents
53+
// all valid string values.
54+
//
55+
// Special struct types
4256
//
43-
// Additionally, for a struct containing a *js.Object field, only the content
44-
// of the field will be passed to JavaScript and vice versa.
57+
// To follow....
4558
package js
4659

4760
// Object is a container for a native JavaScript object. Calls to its methods are treated specially by GopherJS and translated directly to their JavaScript syntax. A nil pointer to Object is equal to JavaScript's "null". Object can not be used as a map key.

js/js_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,10 @@ func TestUint8Array(t *testing.T) {
573573
}
574574
}
575575

576+
// Internalize is used as a helper type to test $internalize. A struct is used
577+
// in order that all of the Go types can be verified (otherwise we are limited
578+
// to the methods on *Object). Where methods on *Object exist they too will be
579+
// tested
576580
type Internalize struct {
577581
*js.Object
578582

0 commit comments

Comments
 (0)