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
-
.are_both_numbers_or_strings ⇒ Object
Optimized helpers for calls like $truthy((a)'$===') -> $eqeqeq(a, b).
-
.const_get_name ⇒ Object
Get the constant in the scope of the current cref.
-
.const_lookup_ancestors ⇒ Object
Walk up the ancestors chain looking for the constant.
-
.const_lookup_nesting ⇒ Object
Walk up the nesting array looking for the constant.
-
.const_lookup_Object ⇒ Object
Walk up Object's ancestors chain looking for the constant, but only if cref is missing or a module.
-
.const_missing ⇒ Object
Call const_missing if nothing else worked.
-
.create_dummy_iclass ⇒ Object
Dummy iclass doesn't receive updates when the module gets a new method.
-
.set_meta ⇒ Object
helper to set $$meta on klass, module or instance.
-
.top_define_method ⇒ Object
Foward calls to define_method on the top object to Object.
Class Method Details
.are_both_numbers_or_strings ⇒ Object
Optimized helpers for calls like $truthy((a)'$===') -> $eqeqeq(a, b)
140 141 142 143 144 145 146 147 |
# File 'opal/opal/corelib/runtime.js.rb', line 140 def self.are_both_numbers_or_strings(*) <<-JAVASCRIPT function are_both_numbers_or_strings(lhs, rhs) { return (typeof lhs === 'number' && typeof rhs === 'number') || (typeof lhs === 'string' && typeof rhs === 'string'); } JAVASCRIPT end |
.const_get_name ⇒ Object
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_ancestors ⇒ Object
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 = $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_nesting ⇒ Object
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_Object ⇒ Object
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_missing ⇒ Object
Call const_missing if nothing else worked
80 81 82 83 84 85 86 |
# File 'opal/opal/corelib/runtime.js.rb', line 80 def self.const_missing(*) <<-JAVASCRIPT function const_missing(cref, name) { return (cref || _Object).$const_missing(name); } JAVASCRIPT end |
.create_dummy_iclass ⇒ Object
Dummy iclass doesn't receive updates when the module gets a new method.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'opal/opal/corelib/runtime.js.rb', line 112 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]; $prop(iclass, prop, proto[prop]); } $prop(iclass, '$$iclass', true); $prop(iclass, '$$module', module); return iclass; } JAVASCRIPT end |
.set_meta ⇒ Object
helper to set $$meta on klass, module or instance
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'opal/opal/corelib/runtime.js.rb', line 90 def self.(*) <<-JAVASCRIPT function set_meta(obj, meta) { if (obj.hasOwnProperty('$$meta')) { obj.$$meta = meta; } else { $prop(obj, '$$meta', meta); } if (obj.$$frozen) { // If a object is frozen (sealed), freeze $$meta too. // No need to inject $$meta.$$prototype in the prototype chain, // as $$meta cannot be modified anyway. obj.$$meta.$freeze(); } else { $set_proto(obj, meta.$$prototype); } }; JAVASCRIPT end |
.top_define_method ⇒ Object
Foward calls to define_method on the top object to Object
151 152 153 154 155 156 157 158 159 160 |
# File 'opal/opal/corelib/runtime.js.rb', line 151 def self.top_define_method(*) <<-JAVASCRIPT function top_define_method() { var args = Opal.slice.call(arguments); var block = top_define_method.$$p; top_define_method.$$p = null; return Opal.send(_Object, 'define_method', args, block) }; JAVASCRIPT end |