1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

Add experimental jasmine support

This commit is contained in:
Charles Lowell 2010-06-02 16:10:24 +03:00
parent f12ce20015
commit 3974fc1f7c
7 changed files with 2423 additions and 0 deletions

22
contrib/v8/jasmine.rb Normal file
View file

@ -0,0 +1,22 @@
module V8
module Jasmine
FILENAME = File.join(File.dirname(__FILE__), "jasmine",Dir.new(File.join(File.dirname(__FILE__), "jasmine")).find {|f| f =~ /(\d+.\d+\.\d+)\.js$/})
VERSION = $1
SOURCE = File.read(FILENAME)
class << self
def included(mod)
raise ScriptError, "#{self} cannot be included. Use cxt.extend(V8::Jasmine)"
end
def extended(cxt)
raise ScriptError, "#{self} can only extend a V8::Context" unless cxt.kind_of?(V8::Context)
cxt.load(File.join(File.dirname(__FILE__), "jasmine", "window.js"))
cxt.load(FILENAME)
end
end
end
end
require 'v8/jasmine/context'

View file

@ -0,0 +1,13 @@
module V8
module Jasmine
class Context < V8::Context
def initialize(*args)
super(*args) do
self.extend V8::Jasmine
yield(self) if block_given?
end
end
end
end
end

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,9 @@
//needed to get around
(function(noop){
window = {
setInterval: noop,
clearInterval: noop,
setTimeout: noop,
clearTimeout: noop
}
})(function() {})

View file

@ -6,6 +6,14 @@
using namespace v8;
namespace {
VALUE New(VALUE self, VALUE source, VALUE source_name) {
HandleScope scope;
Local<String> src(rr_rb2v8(source)->ToString());
Local<String> src_name(rr_rb2v8(source_name)->ToString());
return rr_v8_ref_create(self, Script::Compile(src, src_name));
}
VALUE Compile(VALUE self, VALUE source, VALUE source_name) {
Local<String> src(rr_rb2v8(source)->ToString());
Local<String> src_name(rr_rb2v8(source_name)->ToString());
@ -21,6 +29,7 @@ namespace {
void rr_init_script() {
VALUE ScriptClass = rr_define_class("Script");
rr_define_singleton_method(ScriptClass, "New", New, 2);
rr_define_singleton_method(ScriptClass, "Compile", Compile, 2);
rr_define_method(ScriptClass, "Run", Run, 0);
rb_funcall(ScriptClass, rb_intern("private_class_method"), 1, rb_str_new2("new"));

View file

@ -0,0 +1,38 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require 'v8/jasmine'
describe V8::Jasmine do
it "cannot be included" do
lambda {
Class.new.send(:include, V8::Jasmine)
}.should raise_error(ScriptError)
end
it "can only be used to extend V8::Context objecs" do
lambda {
V8::Context.new.extend(V8::Jasmine)
}.should_not raise_error
lambda {
Object.new.extend(V8::Jasmine)
}.should raise_error(ScriptError)
end
it "extends a bare context with the jasmine runtime" do
V8::Context.new do |cxt|
cxt.extend V8::Jasmine
cxt['jasmine'].should_not be_nil
end
end
end
describe V8::Jasmine::Context do
it "comes pre-bundled with jasmine" do
V8::Jasmine::Context.new do |cxt|
cxt['jasmine'].should_not be_nil
end
end
end

View file

@ -11,6 +11,7 @@ end
# $: is the load path $LOAD_PATH
#
$:.unshift(File.dirname(__FILE__) + '/../lib')
$:.unshift(File.dirname(__FILE__) + '/../contrib')
$:.unshift(File.dirname(__FILE__) + '/..')
require 'v8'