File tree 2 files changed +25
-7
lines changed
2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,11 @@ def setup(native_options)
12
12
13
13
list = Native . make_function_list ( Script . custom_functions . count )
14
14
15
- functions = FunctionWrapper . extend ( Script ::Functions )
15
+ # use an anonymous class wrapper to avoid mutations in a threaded environment
16
+ functions = Class . new do
17
+ attr_accessor :options
18
+ include Script ::Functions
19
+ end . new
16
20
functions . options = @options
17
21
18
22
Script . custom_functions . each_with_index do |custom_function , i |
@@ -65,11 +69,5 @@ def error(message)
65
69
$stderr. puts "[SassC::FunctionsHandler] #{ message } "
66
70
Native . make_error ( message )
67
71
end
68
-
69
- class FunctionWrapper
70
- class << self
71
- attr_accessor :options
72
- end
73
- end
74
72
end
75
73
end
Original file line number Diff line number Diff line change @@ -185,6 +185,22 @@ def test_function_that_takes_a_sass_list
185
185
CSS
186
186
end
187
187
188
+ def test_concurrency
189
+ 10 . times do
190
+ threads = [ ]
191
+ 10 . times do |i |
192
+ threads << Thread . new ( i ) do |id |
193
+ out = Engine . new ( "div { url: inspect_options(); }" , { test_key1 : 'test_value' , test_key2 : id } ) . render
194
+ assert_match /test_key1/ , out
195
+ assert_match /test_key2/ , out
196
+ assert_match /test_value/ , out
197
+ assert_match /#{ id } / , out
198
+ end
199
+ end
200
+ threads . each ( &:join )
201
+ end
202
+ end
203
+
188
204
private
189
205
190
206
def assert_sass ( sass , expected_css )
@@ -279,6 +295,10 @@ def inspect_list(argument)
279
295
return argument
280
296
end
281
297
298
+ def inspect_options
299
+ SassC ::Script ::Value ::String . new ( self . options . inspect , :string )
300
+ end
301
+
282
302
def returns_sass_value
283
303
return SassC ::Script ::Value ::Color . new ( red : 0 , green : 0 , blue : 0 )
284
304
end
You can’t perform that action at this time.
0 commit comments