Class: Browser::Console

Inherits:
Object show all
Includes:
NativeCachedWrapper
Defined in:
opal/browser/console.rb

Overview

Manipulate the browser console.

Instance Method Summary collapse

Methods included from NativeCachedWrapper

#restricted?, #set_native_reference

Instance Method Details

#clearObject

Clear the console.



13
14
15
# File 'opal/browser/console.rb', line 13

def clear
  `#@native.clear()`
end

#error(*args) ⇒ Object

Log the passed objects based on an optional initial format as error.



39
40
41
# File 'opal/browser/console.rb', line 39

def error(*args)
  `#@native.error.apply(#@native, args)`
end

#group(*args, &block) ⇒ Object

Group the given block.

Raises:

  • (ArgumentError)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'opal/browser/console.rb', line 61

def group(*args, &block)
  raise ArgumentError, "no block given" unless block

  `#@native.group.apply(#@native, args)`

  begin
    if block.arity == 0
      instance_exec(&block)
    else
      block.call(self)
    end
  ensure
    `#@native.groupEnd()`
  end
end

#group!(*args, &block) ⇒ Object

Group the given block but collapse it.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'opal/browser/console.rb', line 78

def group!(*args, &block)
  return unless block_given?

  `#@native.groupCollapsed.apply(#@native, args)`

  begin
    if block.arity == 0
      instance_exec(&block)
    else
      block.call(self)
    end
  ensure
    `#@native.groupEnd()`
  end
end

#info(*args) ⇒ Object

Log the passed objects based on an optional initial format as informational log.



29
30
31
# File 'opal/browser/console.rb', line 29

def info(*args)
  `#@native.info.apply(#@native, args)`
end

#log(*args) ⇒ Object

Log the passed objects based on an optional initial format.



23
24
25
# File 'opal/browser/console.rb', line 23

def log(*args)
  `#@native.log.apply(#@native, args)`
end

#time(label, &block) ⇒ Object

Time the given block with the given label.

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'opal/browser/console.rb', line 44

def time(label, &block)
  raise ArgumentError, "no block given" unless block

  `#@native.time(label)`

  begin
    if block.arity == 0
      instance_exec(&block)
    else
      block.call(self)
    end
  ensure
    `#@native.timeEnd()`
  end
end

#traceObject

Print a stacktrace from the call site.



18
19
20
# File 'opal/browser/console.rb', line 18

def trace
  `#@native.trace()`
end

#warn(*args) ⇒ Object

Log the passed objects based on an optional initial format as warning.



34
35
36
# File 'opal/browser/console.rb', line 34

def warn(*args)
  `#@native.warn.apply(#@native, args)`
end