diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index e93dcba..98c49ab 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -13,14 +13,13 @@ module Liquid # # context['bob'] #=> nil class Context class Context - attr_reader :scopes, :errors, :registers, :environments, :resource_limits + attr_reader :scopes, :registers, :environments, :resource_limits attr_accessor :exception_handler def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = nil) @environments = [environments].flatten @scopes = [(outer_scope || {})] @registers = registers - @errors = [] @resource_limits = resource_limits || ResourceLimits.new(Template.default_resource_limits) squash_instance_assigns_with_environments @@ -30,10 +29,14 @@ module Liquid self.exception_handler = ->(e) { true } end - @interrupts = [] + @interrupts = nil @filters = [] end + def errors + @errors ||= [] + end + def strainer @strainer ||= Strainer.create(self, @filters) end @@ -50,17 +53,17 @@ module Liquid # are there any not handled interrupts? def has_interrupt? - !@interrupts.empty? + @interrupts && !@interrupts.empty? end # push an interrupt to the stack. this interrupt is considered not handled. def push_interrupt(e) - @interrupts.push(e) + (@interrupts ||= []).push(e) end # pop an interrupt from the stack def pop_interrupt - @interrupts.pop + @interrupts.pop if @interrupts end diff --git a/test/unit/context_unit_test.rb b/test/unit/context_unit_test.rb index b649483..bf226f7 100644 --- a/test/unit/context_unit_test.rb +++ b/test/unit/context_unit_test.rb @@ -465,6 +465,7 @@ class ContextUnitTest < Minitest::Test mock_empty = Spy.on_instance_method(Array, :empty?) mock_has_interrupt = Spy.on(@context, :has_interrupt?).and_call_through + @context.push_interrupt(StandardError.new) @context.has_interrupt? refute mock_any.has_been_called?