This file is indexed.

/usr/include/gnash/vm/fn_call.h is in gnash-dev 0.8.11~git20160109-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
// 
//   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
//   Free Software Foundation, Inc
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

#ifndef GNASH_FN_CALL_H
#define GNASH_FN_CALL_H

#include <string>
#include <vector>
#include <cassert> 
#include <ostream>
#include <algorithm>

#include "utility.h" // for typeName
#include "as_object.h"
#include "as_value.h"
#include "VM.h"
#include "GnashException.h"
#include "as_environment.h"


// Forward declarations
namespace gnash {
    class movie_definition;
}

namespace gnash {

/// A class to contain transferable arguments for a fn_call.
//
/// The operators += and , are implemented for intuitive syntax:
//
/// FunctionArgs<as_value> args; args += 0.0, "string", NaN.
//
/// This may have unexpected side effects if it is used in unexpected ways,
/// so stick to using such lists, or use operator += repeatedly.
//
/// The arguments can be moved to another container, and this happens when
/// the FunctionArgs object is passed to fn_call. It will still be valid
/// afterwards, but will contain no arguments.
template<typename T>
class FunctionArgs
{
public:

    typedef typename std::vector<T>::size_type size_type;
    typedef std::vector<T> container_type;
    typedef T value_type;

    FunctionArgs() = default;
    FunctionArgs(FunctionArgs&& other) = default;

    /// The copy constructor copies all the arguments.
    FunctionArgs(const FunctionArgs& other) = default;

    FunctionArgs& operator+=(T t) {
        _v.push_back(std::move(t));
        return *this;
    }

    FunctionArgs& operator,(T t) {
        _v.push_back(std::move(t));
        return *this;
    }

    template <typename U>
    FunctionArgs& operator,(U&& u) {
        _v.emplace_back(std::forward<U>(u));
        return *this;
    }

    template <typename U>
    FunctionArgs& operator+=(U&& u) {
        _v.emplace_back(std::forward<U>(u));
        return *this;
    }

    /// Mark any reachable resources
    //
    /// This is only for cases where the lifetime of a FunctionArgs object
    /// extends beyond a function call.
    void setReachable() const {
        std::for_each(_v.begin(), _v.end(),
                      std::mem_fun_ref(&as_value::setReachable));
    }

    void swap(std::vector<T>& to) {
        std::swap(_v, to);
    }

    size_type size() const {
        return _v.size();
    }

private:
    std::vector<T> _v;
};


/// \brief
/// Parameters/environment for builtin or user-defined functions
/// callable from ActionScript.
class fn_call
{
public:

    typedef FunctionArgs<as_value> Args;

    /// Construct a fn_call
    //
    /// @param isNew        Pass true if this is a constructing fn_call,
    ///                     i.e. if it is called as a result of 'new'.
    /// @param super        Pass an overridden super value to the function
    ///                     call. If this is 0, the super reference will be
    ///                     calculated from the this pointer (if that is not
    ///                     null) whenever a function requires it.
    fn_call(as_object* this_in, const as_environment& env_in,
            Args& args, as_object* sup = nullptr, bool isNew = false)
        :
        this_ptr(this_in),
        super(sup),
        nargs(args.size()),
        callerDef(nullptr),
        _env(env_in),
        _new(isNew)
    {
        args.swap(_args);
    }
    
    fn_call(as_object* this_in, const as_environment& env_in)
        :
        this_ptr(this_in),
        super(nullptr),
        nargs(0),
        callerDef(nullptr),
        _env(env_in),
        _new(false)
	{
	}
    
    /// Copy constructor
    fn_call(const fn_call& fn)
        :
        this_ptr(fn.this_ptr),
        super(fn.super),
        nargs(fn.nargs),
        callerDef(fn.callerDef),
        _env(fn._env),
        _args(fn._args),
        _new(false)
	{
	}
    
    /// The as_object (or a pointer derived thereof) on which this call
    /// is taking place.
    as_object* this_ptr;
    
    /// The "super" object in this function call context
    //
    /// If this is 0, the super may be constructed from the this pointer.
    as_object* super;
    
    /// Number of arguments to this ActionScript function call.
    Args::size_type nargs;
    
    /// Definition containing caller code. 0 if spontaneous (system event).
    const movie_definition* callerDef;
    
    /// Return the VM this fn_call is running from
    VM& getVM() const {
        return _env.getVM();
    }
    
    /// Return true if this call is an object instantiation
    bool isInstantiation() const {
        return _new;
	}
    
    /// Access a particular argument.
    const Args::value_type& arg(unsigned int n) const {
        assert(n < nargs);
        return _args[n]; 
	}
    
    const Args::container_type& getArgs() const {
        return _args;
    }
    
    void drop_bottom() {
        assert(!_args.empty());
        _args.erase(_args.begin());
        --nargs;
	}
    
    const as_environment& env() const {
        return _env;
	}
    
    /// Dump arguments to given output stream
    void dump_args(std::ostream& os) const {
        for (size_t i = 0; i < nargs; ++i) {
            if (i) os << ", ";
            os << arg(i);
        }
	}
    
    void resetArgs() {
        nargs = 0;
        _args.clear();
	}
    
    void pushArg(const Args::value_type& arg) {
        ++nargs;
        _args.push_back(arg);
	}
    
private:

    /// The ActionScript environment in which the function call is taking
    /// place. This contains, among other things, the function arguments.
    const as_environment& _env;
    
    /// The actual arguments
    Args::container_type _args;
    
    bool _new;
    
};


/// Check that the 'this' pointer has a particular native type ('Relay').
//
/// This is the most likely of the cases to reflect AS behaviour.
template<typename T>
struct ThisIsNative
{
    typedef T value_type;
    value_type* operator()(const as_object* o) const {
        return dynamic_cast<value_type*>(o->relay());
    }
};

/// Check that the 'this' pointer is a DisplayObject
//
/// By default this just checks for any DisplayObject type.
template<typename T = DisplayObject>
struct IsDisplayObject
{
    typedef T value_type;
    value_type* operator()(const as_object* o) const {
        if (!o) return nullptr;
        return dynamic_cast<T*>(o->displayObject());
    }
};

/// Check that the 'this' pointer is not null.
struct ValidThis
{
    typedef as_object value_type;
    value_type* operator()(as_object* o) const {
        return o;
    }
};

/// Templated function to check the validity of a function call.
//
/// It throws an exception if the condition is not fulfilled, it throws
/// an ActionTypeError, resulting in the function call being aborted and
/// an undefined as_value returned.
//
/// Note that not carrying out a function because the this pointer is
/// undefined is not ActionScript behaviour in most cases. To avoid
/// spreading its usage outside AS function implementations, this function
/// now takes a fn_call as an argument.
//
/// @tparam T       A struct defining a value_type and an operator() that
///                 checks the as_object's validity. A pointer to the
///                 value_type is returned on success, an exception thrown
///                 on failure.
/// @param fn       The function whose 'this' pointer should be checked.
/// @return         If the cast succeeds, the pointer cast to the
///                 requested type.
template<typename T>
typename T::value_type*
ensure(const fn_call& fn)
{
    as_object* obj = fn.this_ptr;
    if (!obj) throw ActionTypeError();
    
    typename T::value_type* ret = T()(obj);
    
    if (!ret) {
        std::string target = typeName(ret);
        std::string source = typeName(obj);

        std::string msg = "Function requiring " + target + " as 'this' "
            "called from " + source + " instance.";

        throw ActionTypeError(msg);
    }
    return ret;
}

inline string_table&
getStringTable(const fn_call& fn)
{
    return fn.getVM().getStringTable();
}

inline movie_root&
getRoot(const fn_call& fn)
{
    return fn.getVM().getRoot();
}

inline int
getSWFVersion(const fn_call& fn)
{
    return fn.getVM().getSWFVersion();
}

inline VM&
getVM(const fn_call& fn)
{
    return fn.getVM();
}

inline Global_as&
getGlobal(const fn_call& fn)
{
    return *fn.getVM().getGlobal();
}

} // namespace gnash


#endif 


// Local Variables:
// mode: C++
// indent-tabs-mode: nil
// End: