Changeset 14655


Ignore:
Timestamp:
11/19/12 00:04:52 (12 years ago)
Author:
tbretz
Message:
Implemented onchange callback as second function in Subscription constructor; enforce strict mode if possible.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/InterpreterV8.cc

    r14643 r14655  
    11461146Handle<Value> InterpreterV8::FuncSubscription(const Arguments &args)
    11471147{
    1148     if (args.Length()!=1)
    1149         return ThrowException(String::New("Number of arguments must be exactly 1."));
     1148    if (args.Length()!=1 && args.Length()!=2)
     1149        return ThrowException(String::New("Number of arguments must be one or two."));
    11501150
    11511151    if (!args[0]->IsString())
    11521152        return ThrowException(String::New("Argument 1 must be a string."));
     1153
     1154    if (args.Length()==2 && !args[1]->IsFunction())
     1155        return ThrowException(String::New("Argument 2 must be a function."));
    11531156
    11541157    const String::AsciiValue str(args[0]);
     
    11631166    }
    11641167
    1165     void *ptr = JsSubscribe(*str);
    1166     if (ptr==0)
    1167         return ThrowException(String::New(("Subscription to '"+string(*str)+"' already exists.").c_str()));
    1168 
    1169     HandleScope handle_scope;
     1168    const HandleScope handle_scope;
    11701169
    11711170    Handle<Object> This = args.This();
     
    11741173    This->Set(String::New("name"),   String::New(*str), ReadOnly);
    11751174    This->Set(String::New("isOpen"), Boolean::New(true));
     1175
     1176    if (args.Length()==2)
     1177        This->Set(String::New("onchange"), args[1]);
     1178
     1179    fReverseMap[*str] = Persistent<Object>::New(This);
     1180
     1181    void *ptr = JsSubscribe(*str);
     1182    if (ptr==0)
     1183        return ThrowException(String::New(("Subscription to '"+string(*str)+"' already exists.").c_str()));
     1184
    11761185    This->SetInternalField(0, External::New(ptr));
    1177 
    1178     fReverseMap[*str] = Persistent<Object>::New(This);
    11791186
    11801187    return Undefined();
     
    16211628//                                  CORE
    16221629// ==========================================================================
     1630
     1631InterpreterV8::InterpreterV8() : fThreadId(-1)
     1632{
     1633    const string ver(V8::GetVersion());
     1634
     1635    typedef boost::char_separator<char> separator;
     1636    const boost::tokenizer<separator> tokenizer(ver, separator("."));
     1637
     1638    const vector<string> tok(tokenizer.begin(), tokenizer.end());
     1639
     1640    const int major = tok.size()>0 ? stol(tok[0]) : -1;
     1641    const int minor = tok.size()>1 ? stol(tok[1]) : -1;
     1642    const int build = tok.size()>2 ? stol(tok[2]) : -1;
     1643
     1644    if (major>3 || (major==3 && minor>9) || (major==3 && minor==9 && build>10))
     1645    {
     1646        const string argv = "--use_strict";
     1647        V8::SetFlagsFromString(argv.c_str(), argv.size());
     1648    }
     1649
     1650    This = this;
     1651}
    16231652
    16241653Handle<Value> InterpreterV8::Constructor(/*Handle<FunctionTemplate> T,*/ const Arguments &args)
     
    16971726bool InterpreterV8::JsRun(const string &filename, const map<string, string> &map)
    16981727{
    1699     //const string argv = "--prof";
    1700     //V8::SetFlagsFromString(argv.c_str(), argv.size());
    1701 
    17021728    const Locker locker;
    17031729    fThreadId = V8::GetCurrentThreadId();
Note: See TracChangeset for help on using the changeset viewer.