mirror of
				https://github.com/rubyjs/therubyrhino
				synced 2023-03-27 23:21:34 -04:00 
			
		
		
		
	allow try-catch-ing ScriptError (besides StandardError) in JS
This commit is contained in:
		
							parent
							
								
									6918349af9
								
							
						
					
					
						commit
						03d30b881b
					
				
					 3 changed files with 21 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
=== 1.73.3 2012-xx-xx
 | 
			
		||||
RedJS 0.4 compatible
 | 
			
		||||
 | 
			
		||||
* allow try-catch-ing ScriptError (besides StandardError) in JS
 | 
			
		||||
* support for yield in JS property access via the [], []= methods
 | 
			
		||||
* refactor access implementations to classes + introduce a shared base
 | 
			
		||||
* missing explicit require 'rhino/version'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -196,7 +196,7 @@ module Rhino
 | 
			
		|||
              @callable
 | 
			
		||||
            end
 | 
			
		||||
          result = callable.call(*rb_args)
 | 
			
		||||
        rescue StandardError => e
 | 
			
		||||
        rescue StandardError, ScriptError => e
 | 
			
		||||
          raise Ruby.wrap_error(e) # thus `try { } catch (e)` works in JS
 | 
			
		||||
        end
 | 
			
		||||
        Rhino.to_javascript(result, scope)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,6 +7,25 @@ puts "will run JavaScript specs from RedJS #{RedJS::VERSION}"
 | 
			
		|||
describe Rhino::Context do
 | 
			
		||||
  
 | 
			
		||||
  it_behaves_like 'RedJS::Context'
 | 
			
		||||
 | 
			
		||||
  # TODO: remove if present in RedJS
 | 
			
		||||
  it "catched ScriptError in JS" do
 | 
			
		||||
    klass = Class.new do
 | 
			
		||||
      def muu(*args)
 | 
			
		||||
        args && raise(ScriptError.new('muu'))
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    error = nil
 | 
			
		||||
    lambda {
 | 
			
		||||
      RedJS::Context.new do |cxt|
 | 
			
		||||
        cxt['obj'] = klass.new
 | 
			
		||||
        error = cxt.eval('var error; try { obj.muu(); error = null } catch(e) { error = e }')
 | 
			
		||||
      end
 | 
			
		||||
    }.should_not raise_error
 | 
			
		||||
    error.should_not be nil
 | 
			
		||||
    error.should be_a ScriptError
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  it "keeps objects iterable when property accessor is provided" do
 | 
			
		||||
    klass = Class.new do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue