Module: __JS__::Opal

Defined in:
opal/opal/corelib/runtime.js.rb

Overview

This module is just a placeholder for showing the documentation of the internal JavaScript runtime. The methods you'll find defined below are actually JavaScript functions attached to the Opal global object

Class Method Summary collapse

Class Method Details

.const_get_nameObject

Get the constant in the scope of the current cref



7
8
9
10
11
12
13
14
15
16
17
18
# File 'opal/opal/corelib/runtime.js.rb', line 7

def self.const_get_name(*)
<<-JAVASCRIPT
   function const_get_name(cref, name) {
     if (cref) {
       if (cref.$$const[name] != null) { return cref.$$const[name]; }
       if (cref.$$autoload && cref.$$autoload[name]) {
         return handle_autoload(cref, name);
       }
     }
   }
JAVASCRIPT
end

.const_lookup_ancestorsObject

Walk up the ancestors chain looking for the constant



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'opal/opal/corelib/runtime.js.rb', line 45

def self.const_lookup_ancestors(*)
<<-JAVASCRIPT
   function const_lookup_ancestors(cref, name) {
     var i, ii, ancestors;
   
     if (cref == null) return;
   
     ancestors = Opal.ancestors(cref);
   
     for (i = 0, ii = ancestors.length; i < ii; i++) {
       if (ancestors[i].$$const && $has_own.call(ancestors[i].$$const, name)) {
         return ancestors[i].$$const[name];
       } else if (ancestors[i].$$autoload && ancestors[i].$$autoload[name]) {
         return handle_autoload(ancestors[i], name);
       }
     }
   }
JAVASCRIPT
end

.const_lookup_nestingObject

Walk up the nesting array looking for the constant



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'opal/opal/corelib/runtime.js.rb', line 22

def self.const_lookup_nesting(*)
<<-JAVASCRIPT
   function const_lookup_nesting(nesting, name) {
     var i, ii, constant;
   
     if (nesting.length === 0) return;
   
     // If the nesting is not empty the constant is looked up in its elements
     // and in order. The ancestors of those elements are ignored.
     for (i = 0, ii = nesting.length; i < ii; i++) {
       constant = nesting[i].$$const[name];
       if (constant != null) {
         return constant;
       } else if (nesting[i].$$autoload && nesting[i].$$autoload[name]) {
         return handle_autoload(nesting[i], name);
       }
     }
   }
JAVASCRIPT
end

.const_lookup_ObjectObject

Walk up Object's ancestors chain looking for the constant, but only if cref is missing or a module.



68
69
70
71
72
73
74
75
76
# File 'opal/opal/corelib/runtime.js.rb', line 68

def self.const_lookup_Object(*)
<<-JAVASCRIPT
   function const_lookup_Object(cref, name) {
     if (cref == null || cref.$$is_module) {
       return const_lookup_ancestors(_Object, name);
     }
   }
JAVASCRIPT
end

.const_missingObject

Call const_missing if nothing else worked



80
81
82
83
84
85
86
87
88
# File 'opal/opal/corelib/runtime.js.rb', line 80

def self.const_missing(*)
<<-JAVASCRIPT
   function const_missing(cref, name, skip_missing) {
     if (!skip_missing) {
       return (cref || _Object).$const_missing(name);
     }
   }
JAVASCRIPT
end

.create_dummy_iclassObject

Dummy iclass doesn't receive updates when the module gets a new method.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'opal/opal/corelib/runtime.js.rb', line 92

def self.create_dummy_iclass(*)
<<-JAVASCRIPT
   function create_dummy_iclass(module) {
     var iclass = {},
         proto = module.$$prototype;
   
     if (proto.hasOwnProperty('$$dummy')) {
       proto = proto.$$define_methods_on;
     }
   
     var props = Object.getOwnPropertyNames(proto),
         length = props.length, i;
   
     for (i = 0; i < length; i++) {
       var prop = props[i];
       $defineProperty(iclass, prop, proto[prop]);
     }
   
     $defineProperty(iclass, '$$iclass', true);
     $defineProperty(iclass, '$$module', module);
   
     return iclass;
   }
JAVASCRIPT
end

.top_define_methodObject

Foward calls to define_method on the top object to Object



120
121
122
123
124
125
126
127
128
129
# File 'opal/opal/corelib/runtime.js.rb', line 120

def self.top_define_method(*)
<<-JAVASCRIPT
   function top_define_method() {
     var args = Opal.slice.call(arguments, 0, arguments.length);
     var block = top_define_method.$$p;
     top_define_method.$$p = null;
     return Opal.send(_Object, 'define_method', args, block)
   };
JAVASCRIPT
end