source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | opal/opal | https://github.com/opal/opal | opal/corelib/boolean.rb | Ruby | mit | 4,915 | master | 2,851 | # use_strict: true
# backtick_javascript: true
class ::Boolean < `Boolean`
`Opal.prop(self.$$prototype, '$$is_boolean', true)`
%x{
var properties = ['$$class', '$$meta'];
for (var i = 0; i < properties.length; i++) {
Object.defineProperty(self.$$prototype, properties[i], {
configurable: tru... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/hash.rb | Ruby | mit | 4,915 | master | 19,032 | # helpers: yield1, hash_clone, hash_delete, hash_each, hash_get, hash_put, deny_frozen_access, freeze, opal32_init, opal32_add
# backtick_javascript: true
# use_strict: true
require 'corelib/enumerable'
# ---
# Internal properties:
#
# - $$keys [Map<key-array>] optional Map of key arrays, used when objects are us... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/variables.rb | Ruby | mit | 4,915 | master | 344 | # backtick_javascript: true
# use_strict: true
# regexp matches
%x{$gvars['&'] = $gvars['~'] = $gvars['`'] = $gvars["'"] = nil}
# requires
$LOADED_FEATURES = $" = `Opal.loaded_features`
$LOAD_PATH = $: = []
# split lines
$/ = "\n"
$, = nil
::ARGV = []
::ARGF = ::Object.new
::ENV = {}
$VERBOSE = false
$DEBUG... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/number.rb | Ruby | mit | 4,915 | master | 18,638 | # backtick_javascript: true
# use_strict: true
require 'corelib/numeric'
class ::Number < ::Numeric
::Opal.bridge(`Number`, self)
`Opal.prop(self.$$prototype, '$$is_number', true)`
`self.$$is_number_class = true`
`var number_id_map = new Map()`
class << self
def allocate
::Kernel.raise ::TypeErro... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/set.rb | Ruby | mit | 4,915 | master | 4,543 | # helpers: freeze
# backtick_javascript: true
# use_strict: true
# Portions Copyright (c) 2002-2013 Akinori MUSHA <knu@iDaemons.org>
class ::Set
include ::Enumerable
def self.[](*ary)
new(ary)
end
def initialize(enum = nil, &block)
@hash = {}
return if enum.nil?
::Kernel.raise ::ArgumentErro... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/nil.rb | Ruby | mit | 4,915 | master | 996 | # backtick_javascript: true
# use_strict: true
class ::NilClass
`self.$$prototype.$$meta = #{self}`
class << self
def allocate
::Kernel.raise ::TypeError, "allocator undefined for #{name}"
end
undef :new
end
def !
true
end
def &(other)
false
end
def |(other)
`other !=... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/dir.rb | Ruby | mit | 4,915 | master | 349 | # backtick_javascript: true
class ::Dir
class << self
def chdir(dir)
prev_cwd = `Opal.current_dir`
`Opal.current_dir = #{dir}`
yield
ensure
`Opal.current_dir = #{prev_cwd}`
end
def pwd
`Opal.current_dir || '.'`
end
def home
::ENV['HOME'] || '.'
end
... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/object_space.rb | Ruby | mit | 4,915 | master | 2,658 | # backtick_javascript: true
# helpers: respond_to, truthy
module ::ObjectSpace
module_function
%x{
var callers = {}, registry, add_caller, delete_callers;
if (typeof FinalizationRegistry === "function") {
registry = new FinalizationRegistry(function(id) {
if (typeof callers[id] !== "undefine... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/class.rb | Ruby | mit | 4,915 | master | 2,528 | # backtick_javascript: true
# use_strict: true
require 'corelib/module'
class ::Class
def self.new(superclass = Object, &block)
%x{
if (!superclass.$$is_class) {
throw Opal.TypeError.$new("superclass must be a Class");
}
var klass = Opal.allocate_class(nil, superclass);
supercla... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/enumerable.rb | Ruby | mit | 4,915 | master | 26,609 | # helpers: truthy, coerce_to, yield1, yieldX, deny_frozen_access
# backtick_javascript: true
# use_strict: true
module ::Enumerable
%x{
function comparableForPattern(value) {
if (value.length === 0) {
value = [nil];
}
if (value.length > 1) {
value = [value];
}
retu... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/irb.rb | Ruby | mit | 4,915 | master | 4,142 | # backtick_javascript: true
# Debug is a helper module that allows us to conduct some debugging on
# a live codebase. It goes with an assumption, that opal-parser or
# opal-replutils will not be loaded, in which case we will do what we can
# to provision it.
require 'runtime/irb'
module Opal
module IRB
def sel... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/file.rb | Ruby | mit | 4,915 | master | 6,574 | # helpers: truthy
# backtick_javascript: true
class ::File < ::IO
Separator = SEPARATOR = '/'
ALT_SEPARATOR = nil
PATH_SEPARATOR = ':'
# Assuming case insenstive filesystem
FNM_SYSCASE = 0
windows_root_rx = %r{^[a-zA-Z]:(?:\\|\/)}
class << self
def absolute_path(path, basedir = nil)
sep = SEPA... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/complex.rb | Ruby | mit | 4,915 | master | 7,798 | # backtick_javascript: true
require 'corelib/numeric'
require 'corelib/complex/base'
class ::Complex < ::Numeric
def self.rect(real, imag = 0)
unless ::Numeric === real && real.real? && ::Numeric === imag && imag.real?
::Kernel.raise ::TypeError, 'not a real'
end
new(real, imag)
end
def self... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/method.rb | Ruby | mit | 4,915 | master | 2,292 | # backtick_javascript: true
class ::Method
attr_reader :owner, :receiver, :name
def initialize(receiver, owner, method, name)
@receiver = receiver
@owner = owner
@name = name
@method = method
end
def arity
@method.arity
end
def parameters
`#{@method}.$$parameters`
end
... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/proc.rb | Ruby | mit | 4,915 | master | 4,410 | # helpers: slice, each_ivar
# backtick_javascript: true
# use_strict: true
class ::Proc < `Function`
`Opal.prop(self.$$prototype, '$$is_proc', true)`
`Opal.prop(self.$$prototype, '$$is_lambda', false)`
def self.new(&block)
unless block
::Kernel.raise ::ArgumentError, 'tried to create a Proc object wit... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/process/status.rb | Ruby | mit | 4,915 | master | 306 | module ::Process
class Status
def initialize(status, pid)
@status, @pid = status, pid
end
def exitstatus
@status
end
attr_reader :pid
def success?
@status == 0
end
def inspect
"#<Process::Status: pid #{@pid} exit #{@status}>"
end
end
end |
github | opal/opal | https://github.com/opal/opal | opal/corelib/pack_unpack/format_string_parser.rb | Ruby | mit | 4,915 | master | 2,941 | # backtick_javascript: true
module ::PackUnpack
%x{
var directives = [
// Integer
'C',
'S',
'L',
'Q',
'J',
'c',
's',
'l',
'q',
'j',
'n',
'N',
'v',
'V',
'U',
'w',
// Float
'D',
'd',
'F... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/enumerator/arithmetic_sequence.rb | Ruby | mit | 4,915 | master | 4,193 | # backtick_javascript: true
# use_strict: true
class ::Enumerator
class self::ArithmeticSequence < self
`Opal.prop(self.$$prototype, '$$is_arithmetic_seq', true)`
`var inf = Infinity`
# @private
def initialize(range, step = undefined, creation_method = :step)
@creation_method = creation_metho... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/enumerator/chain.rb | Ruby | mit | 4,915 | master | 915 | # helpers: deny_frozen_access
# backtick_javascript: true
# use_strict: true
class ::Enumerator
class self::Chain < self
def initialize(*enums)
`$deny_frozen_access(self)`
@enums = enums
@iterated = []
@object = self
end
def each(*args, &block)
return to_enum(:each, *args)... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/enumerator/yielder.rb | Ruby | mit | 4,915 | master | 589 | # backtick_javascript: true
# use_strict: true
class Enumerator
class Yielder
def initialize(&block)
@block = block
# rubocop:disable Lint/Void
self
# rubocop:enable Lint/Void
end
def yield(*values)
%x{
var value = Opal.yieldX(#{@block}, values);
if (value ... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/enumerator/lazy.rb | Ruby | mit | 4,915 | master | 5,662 | # helpers: truthy, coerce_to, yield1, yieldX, deny_frozen_access
# backtick_javascript: true
# use_strict: true
class ::Enumerator
class self::Lazy < self
class self::StopLazyError < ::Exception; end
def self.for(object, *)
lazy = super
`lazy.enumerator = object`
lazy
end
def init... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/enumerator/generator.rb | Ruby | mit | 4,915 | master | 683 | # helpers: deny_frozen_access
# backtick_javascript: true
# use_strict: true
class Enumerator
class Generator
include ::Enumerable
def initialize(&block)
`$deny_frozen_access(self)`
::Kernel.raise ::LocalJumpError, 'no block given' unless block
@block = block
end
def each(*args,... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/pattern_matching/base.rb | Ruby | mit | 4,915 | master | 819 | class ::Array
def deconstruct
self
end
end
class ::Hash
def deconstruct_keys(_)
self
end
end
class ::Struct
alias deconstruct to_a
# This function is specified in a very weird way...
def deconstruct_keys(keys)
return to_h if keys.nil?
::Kernel.raise ::TypeError, 'expected Array or nil' u... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/math/polyfills.rb | Ruby | mit | 4,915 | master | 2,143 | # backtick_javascript: true
# Polyfills for browsers in the age of IE11
unless defined?(`Math.acosh`)
%x{
Math.acosh = function(x) {
return Math.log(x + Math.sqrt(x * x - 1));
}
}
end
unless defined?(`Math.asinh`)
%x{
Math.asinh = function(x) {
return Math.log(x + Math.sqrt(x * x + 1))
... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/string/unpack.rb | Ruby | mit | 4,915 | master | 21,687 | # backtick_javascript: true
require 'base64'
require 'corelib/pack_unpack/format_string_parser'
class ::String
%x{
// Format Parser
var eachDirectiveAndCount = Opal.PackUnpack.eachDirectiveAndCount;
function flattenArray(callback) {
return function(data) {
var array = callback(data);
... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/string/encoding.rb | Ruby | mit | 4,915 | master | 26,342 | # backtick_javascript: true
# helpers: str
class ::Encoding
class << self
def register(name, options = {}, &block)
names = [name] + (options[:aliases] || [])
ascii = options[:ascii] || false
dummy = options[:dummy] || false
if options[:inherits]
encoding = options[:inherits].clon... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/string/encoding/dummy.rb | Ruby | mit | 4,915 | master | 765 | # backtick_javascript: true
require 'corelib/string/encoding'
# these encodings are required for some ruby specs, make them dummy for now
# their existence is often enough, like specs checking if a method returns
# a new string in the same encoding it was orginally encoded in
::Encoding.register 'IBM437', inherits: :... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/string/encoding/jis.rb | Ruby | mit | 4,915 | master | 8,487 | # backtick_javascript: true
# helpers: str
# inspired by
# Jconv
# Copyright (c) 2013-2014 narirou
# MIT Licensed
# https://github.com/narirou/jconv
# modified for Opal:
# https://github.com/janbiedermann/jconv/tree/for_opal
# only converts UCS2/UTF16 string to JIS/SJIS/EUCJP byte buffer
# performance:
# https://githu... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/string/encoding/eucjp.rb | Ruby | mit | 4,915 | master | 5,828 | # backtick_javascript: true
# helpers: str
# inspired by
# Jconv
# Copyright (c) 2013-2014 narirou
# MIT Licensed
# https://github.com/narirou/jconv
# modified for Opal:
# https://github.com/janbiedermann/jconv/tree/for_opal
# only converts UCS2/UTF16 string to JIS/SJIS/EUCJP byte buffer
# performance:
# https://githu... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/string/encoding/sjis.rb | Ruby | mit | 4,915 | master | 4,549 | # backtick_javascript: true
# helpers: str
# inspired by
# Jconv
# Copyright (c) 2013-2014 narirou
# MIT Licensed
# https://github.com/narirou/jconv
# modified for Opal:
# https://github.com/janbiedermann/jconv/tree/for_opal
# only converts UCS2/UTF16 string to JIS/SJIS/EUCJP byte buffer
# performance:
# https://githu... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/string/encoding/tables/sjis_inverted.rb | Ruby | mit | 4,915 | master | 87,715 | # backtick_javascript: true
%x{Opal.Encoding.SJISInverted={162:33169,163:33170,166:61178,167:33176,168:33102,172:33226,176:33163,177:33149,180:33100,182:33271,215:33150,247:33152,913:33695,914:33696,915:33697,916:33698,917:33699,918:33700,919:33701,920:33702,921:33703,922:33704,923:33705,924:33706,925:33707,926:33708,9... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/string/encoding/tables/jis_ext_inverted.rb | Ruby | mit | 4,915 | master | 72,341 | # backtick_javascript: true
%x{Opal.Encoding.JISEXTInverted={126:8759,161:8770,164:8816,166:8771,169:8813,170:8812,174:8814,175:8756,184:8753,186:8811,191:8772,192:10786,193:10785,194:10788,195:10794,196:10787,197:10793,198:10529,199:10798,200:10802,201:10801,202:10804,203:10803,204:10816,205:10815,206:10818,207:10817,... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/string/encoding/tables/jis_inverted.rb | Ruby | mit | 4,915 | master | 87,262 | # backtick_javascript: true
%x{Opal.Encoding.JISInverted={92:8512,162:8561,163:8562,167:8568,168:8495,172:8780,176:8555,177:8542,180:8493,182:8825,215:8543,247:8544,913:9761,914:9762,915:9763,916:9764,917:9765,918:9766,919:9767,920:9768,921:9769,922:9770,923:9771,924:9772,925:9773,926:9774,927:9775,928:9776,929:9777,93... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/error/errno.rb | Ruby | mit | 4,915 | master | 1,158 | # backtick_javascript: true
# use_strict: true
module ::Errno
errors = [
[:EINVAL, 'Invalid argument', 22],
[:EEXIST, 'File exists', 17],
[:EISDIR, 'Is a directory', 21],
[:EMFILE, 'Too many open files', 24],
[:ESPIPE, 'Illegal seek', 29],
[:EACCES, 'Permission denied', 13],
[:EPERM, 'Ope... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/array/pack.rb | Ruby | mit | 4,915 | master | 13,055 | # helpers: coerce_to
# backtick_javascript: true
require 'corelib/pack_unpack/format_string_parser'
class ::Array
%x{
// Format Parser
var eachDirectiveAndCount = Opal.PackUnpack.eachDirectiveAndCount;
function identityFunction(value) { return value; }
function utf8BytesToUtf16LEString(bytes) {
... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/io/buffer.rb | Ruby | mit | 4,915 | master | 22,907 | # backtick_javascript: true
require 'corelib/string/encoding'
class ::IO
class Buffer
# Types that can be requested from the buffer:
#
# :U8: unsigned integer, 1 byte
# :S8: signed integer, 1 byte
# :u16: unsigned integer, 2 bytes, little-endian
# :U16: unsigned integer, 2 bytes, big-endian
... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/complex/base.rb | Ruby | mit | 4,915 | master | 211 | module ::Kernel
def Complex(real, imag = nil)
if imag
Complex.new(real, imag)
else
Complex.new(real, 0)
end
end
end
class ::String
def to_c
Complex.from_string(self)
end
end |
github | opal/opal | https://github.com/opal/opal | opal/corelib/random/math_random.js.rb | Ruby | mit | 4,915 | master | 277 | # backtick_javascript: true
# use_strict: true
class ::Random
MATH_RANDOM_GENERATOR = `{
new_seed: function() { return 0; },
reseed: function(seed) { return {}; },
rand: function($rng) { return Math.random(); }
}`
self.generator = MATH_RANDOM_GENERATOR
end |
github | opal/opal | https://github.com/opal/opal | opal/corelib/random/formatter.rb | Ruby | mit | 4,915 | master | 3,125 | # backtick_javascript: true
# use_strict: true
class ::Random
module self::Formatter
def hex(count = nil)
count = ::Random._verify_count(count)
%x{
var bytes = #{bytes(count)};
var out = "";
for (var i = 0; i < #{count}; i++) {
out += bytes.charCodeAt(i).toString(16)... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/random/seedrandom.js.rb | Ruby | mit | 4,915 | master | 2,751 | # backtick_javascript: true
# use_strict: true
class ::Random
%x{
var module = { exports: {} };
/* eslint-disable */
/*
seedrandom.min.js 2.4.1 (original source: https://github.com/davidbau/seedrandom/blob/2.4.1/seedrandom.min.js)
How to update:
. Chekout the latest release from GitHub: htt... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/random/mersenne_twister.rb | Ruby | mit | 4,915 | master | 5,637 | # backtick_javascript: true
# use_strict: true
# This is based on an adaptation of Makoto Matsumoto and Takuji Nishimura's code
# done by Sean McCullough <banksean@gmail.com> and Dave Heitzman
# <daveheitzman@yahoo.com>, subsequently readapted from an updated version of
# ruby's random.c (rev c38a183032a7826df1adabd8a... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/marshal/read_buffer.rb | Ruby | mit | 4,915 | master | 13,048 | # backtick_javascript: true
# https://github.com/ruby/ruby/blob/trunk/doc/marshal.rdoc
# https://github.com/ruby/ruby/blob/trunk/marshal.c
module ::Marshal
class self::ReadBuffer
%x{
function stringToBytes(string) {
var i,
singleByte,
l = string.length,
result =... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/marshal/write_buffer.rb | Ruby | mit | 4,915 | master | 9,160 | # backtick_javascript: true
class ::NilClass
def __marshal__(buffer)
buffer.append('0')
end
end
class ::Boolean
def __marshal__(buffer)
if `self == true`
buffer.append('T')
else
buffer.append('F')
end
end
end
class ::Integer
def __marshal__(buffer)
if self >= -0x40000000 && ... |
github | opal/opal | https://github.com/opal/opal | opal/corelib/kernel/format.rb | Ruby | mit | 4,915 | master | 19,650 | # helpers: coerce_to
# backtick_javascript: true
module ::Kernel
def format(format_string, *args)
if args.length == 1 && args[0].respond_to?(:to_ary)
ary = ::Opal.coerce_to?(args[0], ::Array, :to_ary)
args = ary.to_a unless ary.nil?
end
%x{
var result = '',
//used for slicing... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/regexp.rb | Ruby | mit | 4,915 | master | 2,546 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
module ::Opal
# Escape Regexp special chars letting the resulting string be used to build
# a new Regexp.
def self.escape_regexp(str)
`Opal.escape_metacharacters(str.replace(/([-[\]\/{}()*+?.^$\\| ])/g, '\\$1'))`
end
def self.escap... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/const.rb | Ruby | mit | 4,915 | master | 8,835 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: prop, raise, Object, has_own
module ::Opal
# Walk up the nesting array looking for the constant
def self.const_lookup_nesting(nesting, name)
%x{
var i, ii, constant;
if (nesting.length === 0) return;
// If t... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/op_helpers.rb | Ruby | mit | 4,915 | master | 3,140 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: truthy, deny_frozen_access
# rubocop:disable Layout/EmptyLineBetweenDefs
module ::Opal
# Operator helpers
# ----------------
%x{
function are_both_numbers(l,r) {
return typeof(l) === 'number' && typeof(r) === 'number'... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/module.rb | Ruby | mit | 4,915 | master | 14,288 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: prop, raise, Object, allocate_module, const_get_name, const_lookup_ancestors, ancestors, const_set, set_proto, has_own
module ::Opal
%x{
// TracePoint support
// ------------------
//
// Support for `TracePoint.trace(... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/send.rb | Ruby | mit | 4,915 | master | 3,892 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: apply_blockopts, jsid, raise, prepend_ary, get_ancestors
module ::Opal
# Calls passed method on a ruby object with arguments and block:
#
# Can take a method or a method name.
#
# 1. When method name gets passed it invokes it... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/variables.rb | Ruby | mit | 4,915 | master | 1,519 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
module ::Opal
# Instance variables
# ------------------
%x{
var reserved_ivar_names = [
// properties
"constructor", "displayName", "__count__", "__noSuchMethod__",
"__parent__", "__proto__",
// methods
"h... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/array.rb | Ruby | mit | 4,915 | master | 1,589 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: raise
module ::Opal
# Helpers for implementing multiple assignment
# Our code for extracting the values and assigning them only works if the
# return value is a JS array.
# So if we get an Array subclass, extract the wrapped JS... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/irb.rb | Ruby | mit | 4,915 | master | 703 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: raise, slice, splice, has_own
module ::Opal
# Run in WebTools console with: Opal.irb(c => eval(c))
def self.irb(fun)
::Binding.new(fun).irb
end
def self.load_parser
::Opal::IRB.ensure_loaded('opal-parser')
end
%x{... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/helpers.rb | Ruby | mit | 4,915 | master | 5,399 | # helpers: type_error, coerce_to
# backtick_javascript: true
# use_strict: true
module ::Opal
def self.coerce_to!(object, type, method, *args)
coerced = `$coerce_to(object, type, method, args)`
unless type === coerced
::Kernel.raise `$type_error(object, type, method, coerced)`
end
coerced
e... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/class.rb | Ruby | mit | 4,915 | master | 11,571 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: raise, prop, Object, BasicObject, Class, Module, set_proto, allocate_class, const_get_name, const_set, has_own, ancestors, jsid
module ::Opal
def self.find_existing_class(scope, name)
%x{
// Try to find the class in the cur... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/method.rb | Ruby | mit | 4,915 | master | 13,951 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: deny_frozen_access, prop, has_own, jsid, raise, ancestors, get_ancestors
module ::Opal
# Method creation/deletion
# ------------------------
# Used to define methods on an object. This is a helper method, used by the
# compile... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/exception.rb | Ruby | mit | 4,915 | master | 3,480 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: gvars, Kernel, slice, truthy
module ::Opal
# A helper function for raising things, that gracefully degrades if necessary
# functionality is not yet loaded.
def self.raise(klass, message)
%x{
// Raise Exception, so we ca... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/misc.rb | Ruby | mit | 4,915 | master | 1,154 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: return_val, Object, gvars
module ::Opal
# Create a new range instance with first and last values, and whether the
# range excludes the last value.
def self.range(first, last, exc)
%x{
var range = new Opal.Range(... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/freeze.rb | Ruby | mit | 4,915 | master | 1,898 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: prop, raise, uid, return_val
module ::Opal
# Support for #freeze
# -------------------
# Common #freeze runtime support
def self.freeze(obj)
%x{
$prop(obj, "$$frozen", true);
// set $$id
if (!obj.hasOwnP... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/proc.rb | Ruby | mit | 4,915 | master | 2,411 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: apply_blockopts, raise
module ::Opal
%x{
function call_lambda(block, arg, ret) {
try {
block(arg);
} catch (e) {
if (e === ret) {
return ret.$v;
}
throw e;
}
}
}
... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/runtime.rb | Ruby | mit | 4,915 | master | 488 | require 'runtime/boot'
require 'runtime/variables'
require 'runtime/exception'
require 'runtime/freeze'
require 'runtime/op_helpers'
require 'runtime/method_missing'
require 'runtime/const'
require 'runtime/module'
require 'runtime/class'
require 'runtime/method'
require 'runtime/proc'
require 'runtime/send'
requir... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/bridge.rb | Ruby | mit | 4,915 | master | 2,899 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: raise, prop, set_proto
module ::Opal
# For performance, some core Ruby classes are toll-free bridged to their
# native JavaScript counterparts (e.g. a Ruby Array is a JavaScript Array).
#
# This method is used to setup a native... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/method_missing.rb | Ruby | mit | 4,915 | master | 3,153 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: BasicObject, jsid, prop, prepend_ary
module ::Opal
# Method Missing
# --------------
# Methods stubs are used to facilitate method_missing in opal. A stub is a
# placeholder function which just calls `method_missing` on the re... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/hash.rb | Ruby | mit | 4,915 | master | 11,108 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: raise, slice, splice, has_own
module ::Opal
# Hashes
# ------
# Experiments have shown, that using new Map([[1,2]]) inline is rather slow
# compared to using new Map() in combination with .set(1,2), because the former
# crea... |
github | opal/opal | https://github.com/opal/opal | opal/runtime/string.rb | Ruby | mit | 4,915 | master | 3,736 | # backtick_javascript: true
# use_strict: true
# opal_runtime_mode: true
# helpers: raise, prop, Object
module ::Opal
# We use a helper to create new Strings, globally, so that it
# will be easer to change that later on to a mutable string class.
# Also this helper always sets a encoding. If encoding is not
# ... |
github | opal/opal | https://github.com/opal/opal | stdlib/thread.rb | Ruby | mit | 4,915 | master | 3,221 | # This shim implementation of Thread is meant to only appease code that tries
# to be safe in the presence of threads, but does not actually utilize them,
# e.g., uses thread- or fiber-local variables.
class ThreadError < StandardError
end
class Thread
def self.current
unless @current
@current = allocate
... |
github | opal/opal | https://github.com/opal/opal | stdlib/stringio.rb | Ruby | mit | 4,915 | master | 1,985 | class StringIO < IO
VERSION = "0"
def self.open(string = "", mode = nil, &block)
io = new(string, mode)
res = block.call(io)
io.close
res
end
attr_accessor :string
def initialize(string = "", mode = 'rw')
@string = string
@position = 0
super(nil, mode)
end
def eof?
... |
github | opal/opal | https://github.com/opal/opal | stdlib/ostruct.rb | Ruby | mit | 4,915 | master | 2,760 | # backtick_javascript: true
class OpenStruct
def initialize(hash = nil)
@table = {}
if hash
hash.each_pair do |key, value|
@table[new_ostruct_member(key)] = value
end
end
end
def [](name)
@table[name.to_sym]
end
def []=(name, value)
@table[new_ostruct_member(name)] ... |
github | opal/opal | https://github.com/opal/opal | stdlib/benchmark.rb | Ruby | mit | 4,915 | master | 18,325 | #--
# benchmark.rb - a performance benchmarking library
#
# $Id$
#
# Created by Gotoken (gotoken@notwork.org).
#
# Documentation by Gotoken (original RD), Lyle Johnson (RDoc conversion), and
# Gavin Sinclair (editing).
#++
#
# == Overview
#
# The Benchmark module provides methods for benchmarking Ruby code, giving
# de... |
github | opal/opal | https://github.com/opal/opal | stdlib/time.rb | Ruby | mit | 4,915 | master | 2,087 | # backtick_javascript: true
class Time
def self.parse(str)
%x{
var d = Date.parse(str);
if (d !== d) {
// parsing failed, d is a NaN
// probably str is not in ISO 8601 format, which is the only format, required to be supported by Javascript
// try to make the format more like ... |
github | opal/opal | https://github.com/opal/opal | stdlib/json.rb | Ruby | mit | 4,915 | master | 3,627 | # backtick_javascript: true
module JSON
class JSONError < StandardError
end
class ParserError < JSONError
end
%x{
var $hasOwn = Opal.hasOwnProperty;
function $parse(source) {
try {
return JSON.parse(source);
} catch (e) {
#{raise JSON::ParserError, `e.message`};
}... |
github | opal/opal | https://github.com/opal/opal | stdlib/date.rb | Ruby | mit | 4,915 | master | 13,979 | # backtick_javascript: true
require 'forwardable'
require 'date/infinity'
require 'time'
class Date
include Comparable
extend Forwardable
JULIAN = Infinity.new
GREGORIAN = -Infinity.new
ITALY = 2_299_161 # 1582-10-15
ENGLAND = 2_361_222 # 1752-09-14
MONTHNAMES = [n... |
github | opal/opal | https://github.com/opal/opal | stdlib/pp.rb | Ruby | mit | 4,915 | master | 16,542 | # frozen_string_literal: true
# backtick_javascript: true
# Opal: load stdlib/thread.rb
require 'thread'
require 'stringio'
require 'prettyprint'
##
# A pretty-printer for Ruby objects.
#
##
# == What PP Does
#
# Standard output by #p returns this:
# #<PP:0x81fedf0 @genspace=#<Proc:0x81feda0>, @group_queue=#<Pretty... |
github | opal/opal | https://github.com/opal/opal | stdlib/pathname.rb | Ruby | mit | 4,915 | master | 5,216 | # backtick_javascript: true
require 'corelib/comparable'
# Portions from Author:: Tanaka Akira <akr@m17n.org>
class Pathname
include Comparable
SEPARATOR_PAT = /#{Regexp.quote File::SEPARATOR}/
def initialize(path)
if Pathname === path
@path = path.path.to_s
elsif path.respond_to?(:to_path)
... |
github | opal/opal | https://github.com/opal/opal | stdlib/opal-replutils.rb | Ruby | mit | 4,915 | master | 7,755 | # backtick_javascript: true
# await: true
require 'await'
require 'pp'
require 'stringio'
module REPLUtils
module_function
def ls(object, colorize)
methods = imethods = object.methods
ancestors = object.class.ancestors
constants = []
ivs = object.instance_variables
cvs = []
if [Class, M... |
github | opal/opal | https://github.com/opal/opal | stdlib/buffer.rb | Ruby | mit | 4,915 | master | 818 | # backtick_javascript: true
require 'native'
require 'buffer/array'
require 'buffer/view'
class Buffer
include Native::Wrapper
def self.supported?
!$$[:ArrayBuffer].nil?
end
def self.name_for(bits, type)
part = case type
when :unsigned then 'Uint'
when :signed then 'Int'
... |
github | opal/opal | https://github.com/opal/opal | stdlib/opal-parser.rb | Ruby | mit | 4,915 | master | 2,228 | # helpers: call, raise
# backtick_javascript: true
# parser uses String#unpack
require 'corelib/string/unpack'
require 'opal/compiler'
require 'opal/erb'
require 'opal/version'
module Kernel
def eval(str, binding = nil, file = nil, line = nil)
str = ::Opal.coerce_to!(str, String, :to_str)
default_eval_opti... |
github | opal/opal | https://github.com/opal/opal | stdlib/js.rb | Ruby | mit | 4,915 | master | 341 | # backtick_javascript: true
require 'opal/raw'
warn '[Opal] JS module has been renamed to Opal::Raw and will change semantics in Opal 2.1. ' \
'In addition, you will need to require "opal/raw" instead of "js". ' \
'To ensure forward compatibility, please update your calls.'
module JS
extend Opal::Raw
i... |
github | opal/opal | https://github.com/opal/opal | stdlib/securerandom.rb | Ruby | mit | 4,915 | master | 2,141 | # backtick_javascript: true
require 'corelib/random/formatter'
module SecureRandom
extend Random::Formatter
%x{
var gen_random_bytes;
if ((Opal.global.crypto && Opal.global.crypto.getRandomValues) ||
(Opal.global.msCrypto && Opal.global.msCrypto.getRandomValues)) {
// This method is avai... |
github | opal/opal | https://github.com/opal/opal | stdlib/ruby2_keywords.rb | Ruby | mit | 4,915 | master | 1,233 | # This file ended up in Opal as a port of:
# https://github.com/ruby/ruby2_keywords/blob/master/lib/ruby2_keywords.rb
class Module
unless private_method_defined?(:ruby2_keywords)
private
# call-seq:
# ruby2_keywords(method_name, ...)
#
# Does nothing.
def ruby2_keywords(name, *)
# ni... |
github | opal/opal | https://github.com/opal/opal | stdlib/open-uri.rb | Ruby | mit | 4,915 | master | 9,994 | # frozen_string_literal: true
# backtick_javascript: true
# Copied from https://raw.githubusercontent.com/ruby/ruby/373babeaac8c3e663e1ded74a9f06ac94a671ed9/lib/open-uri.rb
require 'stringio'
require 'corelib/array/pack'
module Kernel
private
alias open_uri_original_open open # :nodoc:
class << self
alias ... |
github | opal/opal | https://github.com/opal/opal | stdlib/delegate.rb | Ruby | mit | 4,915 | master | 12,262 | # frozen_string_literal: true
# helpers: freeze, freeze_props
# backtick_javascript: true
# = delegate -- Support for the Delegation Pattern
#
# This file ended up in Opal as a port of the following file:
# https://github.com/ruby/ruby/blob/master/lib/delegate.rb
#
# Documentation by James Edward Gray II and Gavin Sin... |
github | opal/opal | https://github.com/opal/opal | stdlib/prettyprint.rb | Ruby | mit | 4,915 | master | 16,276 | # frozen_string_literal: true
#
# This class implements a pretty printing algorithm. It finds line breaks and
# nice indentations for grouped structure.
#
# By default, the class assumes that primitive elements are strings and each
# byte in the strings have single column in width. But it can be used for
# other situat... |
github | opal/opal | https://github.com/opal/opal | stdlib/template.rb | Ruby | mit | 4,915 | master | 654 | class Template
@_cache = {}
def self.[](name)
@_cache[name] || @_cache["templates/#{name}"]
end
def self.[]=(name, instance)
@_cache[name] = instance
end
def self.paths
@_cache.keys
end
attr_reader :body
def initialize(name, &body)
@name, @body = name, body
Template[name] = sel... |
github | opal/opal | https://github.com/opal/opal | stdlib/console.rb | Ruby | mit | 4,915 | master | 1,983 | # backtick_javascript: true
require 'native'
# Manipulate the browser console.
#
# @see https://developer.mozilla.org/en-US/docs/Web/API/console
class Console
include Native::Wrapper
# Clear the console.
def clear
`#{@native}.clear()`
end
# Print a stacktrace from the call site.
def trace
`#{@na... |
github | opal/opal | https://github.com/opal/opal | stdlib/opal-platform.rb | Ruby | mit | 4,915 | master | 1,450 | # backtick_javascript: true
`/* global GjsFileImporter, Deno, Bun */`
browser = `typeof(document) !== "undefined"`
bun = `typeof(Bun) === "object" && typeof(Bun.version) === "string"`
deno = `typeof(Deno) === "object" && typeof(Deno.version) === "object"`
node = `typeof(p... |
github | opal/opal | https://github.com/opal/opal | stdlib/uri.rb | Ruby | mit | 4,915 | master | 1,319 | # backtick_javascript: true
# frozen_string_literal: true
module URI
def self.decode_www_form(str, enc = undefined, separator: '&', use__charset_: false, isindex: false)
raise ArgumentError, "the input of #{name}.#{__method__} must be ASCII only string" unless str.ascii_only?
%x{
var ary = [], key, va... |
github | opal/opal | https://github.com/opal/opal | stdlib/matrix.rb | Ruby | mit | 4,915 | master | 54,890 | # encoding: utf-8
# frozen_string_literal: false
#
# = matrix.rb
#
# An implementation of Matrix and Vector classes.
#
# See classes Matrix and Vector for documentation.
#
# Current Maintainer:: Marc-André Lafortune
# Original Author:: Keiju ISHITSUKA
# Original Documentation:: Gavin Sinclair (sourced from <i>Ruby in a... |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs.rb | Ruby | mit | 4,915 | master | 257 | require 'nodejs/base'
require 'nodejs/kernel'
require 'nodejs/process'
require 'nodejs/file'
require 'nodejs/dir'
require 'nodejs/io'
require 'nodejs/argf'
require 'nodejs/open-uri'
require 'nodejs/pathname'
require 'nodejs/env'
require 'nodejs/opal-paths' |
github | opal/opal | https://github.com/opal/opal | stdlib/e2mmap.rb | Ruby | mit | 4,915 | master | 4,038 | # frozen_string_literal: true
#
#--
# e2mmap.rb - for Ruby 1.1
# $Release Version: 2.0$
# $Revision: 1.10 $
# by Keiju ISHITSUKA
#
#++
#
# Helper module for easily defining exceptions with predefined messages.
#
# == Usage
#
# 1.
# class Foo
# extend Exception2MessageMapper
# def_e2message... |
github | opal/opal | https://github.com/opal/opal | stdlib/promise.rb | Ruby | mit | 4,915 | master | 8,702 | # {Promise} is used to help structure asynchronous code.
#
# It is available in the Opal standard library, and can be required in any Opal
# application:
#
# require 'promise'
#
# ## Basic Usage
#
# Promises are created and returned as objects with the assumption that they
# will eventually be resolved or rejected,... |
github | opal/opal | https://github.com/opal/opal | stdlib/rbconfig.rb | Ruby | mit | 4,915 | master | 614 | module RbConfig
versions = RUBY_VERSION.split('.')
CONFIG = {
'ruby_version' => RUBY_VERSION,
'MAJOR' => versions[0],
'MINOR' => versions[1],
'TEENY' => versions[2],
'RUBY' => RUBY_ENGINE,
'RUBY_INSTALL_NAME' => RUBY_ENGINE,
'ruby_install_name' => RUBY_ENGINE... |
github | opal/opal | https://github.com/opal/opal | stdlib/forwardable.rb | Ruby | mit | 4,915 | master | 1,878 | module Forwardable
def instance_delegate(hash)
hash.each do |methods, accessor|
methods = [methods] unless methods.respond_to? :each
methods.each do |method|
def_instance_delegator(accessor, method)
end
end
end
def def_instance_delegators(accessor, *methods)
methods.each do... |
github | opal/opal | https://github.com/opal/opal | stdlib/logger.rb | Ruby | mit | 4,915 | master | 2,310 | # backtick_javascript: true
class Logger
module Severity
DEBUG = 0
INFO = 1
WARN = 2
ERROR = 3
FATAL = 4
UNKNOWN = 5
end
include Severity
SEVERITY_LABELS = Severity.constants.map { |s| [(Severity.const_get s), s.to_s] }.to_h
class Formatter
MESSAGE_FORMAT = "%s, [%s] %5s -- %s: ... |
github | opal/opal | https://github.com/opal/opal | stdlib/singleton.rb | Ruby | mit | 4,915 | master | 776 | module Singleton
def clone
raise TypeError, "can't clone instance of singleton #{self.class}"
end
def dup
raise TypeError, "can't dup instance of singleton #{self.class}"
end
module SingletonClassMethods
def clone
Singleton.__init__(super)
end
def inherited(sub_klass)
super
... |
github | opal/opal | https://github.com/opal/opal | stdlib/observer.rb | Ruby | mit | 4,915 | master | 5,857 | #
# Implementation of the _Observer_ object-oriented design pattern. The
# following documentation is copied, with modifications, from "Programming
# Ruby", by Hunt and Thomas; http://www.ruby-doc.org/docs/ProgrammingRuby/html/lib_patterns.html.
#
# See Observable for more info.
# The Observer pattern (also known as ... |
github | opal/opal | https://github.com/opal/opal | stdlib/await.rb | Ruby | mit | 4,915 | master | 1,991 | # helpers: coerce_to
# await: await
# backtick_javascript: true
%x{
var AsyncFunction = Object.getPrototypeOf(async function() {}).constructor;
}
require 'promise/v2'
class Array
def map_await(&block)
i = 0
results = []
while i < `self.length`
results << yield(self[i]).await
i += 1
en... |
github | opal/opal | https://github.com/opal/opal | stdlib/native.rb | Ruby | mit | 4,915 | master | 13,884 | # backtick_javascript: true
# helpers: hash_put
# Provides a complete set of tools to wrap native JavaScript
# into nice Ruby objects.
#
# @example
#
# $$.document.querySelector('p').classList.add('blue')
# # => adds "blue" class to <p>
#
# $$.location.href = 'https://google.com'
# # => changes page location
#... |
github | opal/opal | https://github.com/opal/opal | stdlib/optparse.rb | Ruby | mit | 4,915 | master | 61,009 | # frozen_string_literal: true
#
# optparse.rb - command-line option analysis with the OptionParser class.
#
# Author:: Nobu Nakada
# Documentation:: Nobu Nakada and Gavin Sinclair.
#
# See OptionParser for documentation.
#
#--
# == Developer Documentation (not for RDoc output)
#
# === Class tree
#
# - OptionParser:: ... |
github | opal/opal | https://github.com/opal/opal | stdlib/base64.rb | Ruby | mit | 4,915 | master | 2,757 | # backtick_javascript: true
module Base64
# FROM https://github.com/davidchambers/Base64.js/blob/69262ec7e1fa4541de5700a1b0b03b0de0e3f5aa/base64.js
%x{
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var encode, decode;
// encoder
// [https://gist.github.com/999166... |
github | opal/opal | https://github.com/opal/opal | stdlib/erb.rb | Ruby | mit | 4,915 | master | 407 | # backtick_javascript: true
require 'template'
class ERB
module Util
`var escapes = { '&': '&', '<': '<', '>': '>', '"': '"', "'": '''};`
`var escape_regexp = /[&<>"']/g;`
def html_escape(str)
`("" + str).replace(escape_regexp, function (m) { return escapes[m] })`
end
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.