mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FEATURE: upgrade from therubyracer to mini_racer
This pushes our internal V8 JavaScript engine from Chrome 32 to 50. It also resolves some long standing issues we had with the old wrapper.
This commit is contained in:
parent
f387dfe226
commit
695773db1c
7 changed files with 70 additions and 68 deletions
|
@ -154,15 +154,25 @@ module JsLocaleHelper
|
|||
result
|
||||
end
|
||||
|
||||
def self.compile_message_format(locale, format)
|
||||
ctx = V8::Context.new
|
||||
ctx.load(Rails.root + 'lib/javascripts/messageformat.js')
|
||||
path = Rails.root + "lib/javascripts/locale/#{locale}.js"
|
||||
ctx.load(path) if File.exists?(path)
|
||||
ctx.eval("mf = new MessageFormat('#{locale}');")
|
||||
ctx.eval("mf.precompile(mf.parse(#{format.inspect}))")
|
||||
@mutex = Mutex.new
|
||||
def self.with_context
|
||||
@mutex.synchronize do
|
||||
yield @ctx ||= begin
|
||||
ctx = MiniRacer::Context.new
|
||||
ctx.load(Rails.root + 'lib/javascripts/messageformat.js')
|
||||
ctx
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
rescue V8::Error => e
|
||||
def self.compile_message_format(locale, format)
|
||||
with_context do |ctx|
|
||||
path = Rails.root + "lib/javascripts/locale/#{locale}.js"
|
||||
ctx.load(path) if File.exists?(path)
|
||||
ctx.eval("mf = new MessageFormat('#{locale}');")
|
||||
ctx.eval("mf.precompile(mf.parse(#{format.inspect}))")
|
||||
end
|
||||
rescue MiniRacer::EvalError => e
|
||||
message = "Invalid Format: " << e.message
|
||||
"function(){ return #{message.inspect};}"
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue