Guest User

Untitled

a guest
Feb 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. static Handle<Value> TracedGetProperty(Local<String> property, const AccessorInfo &info)
  2. {
  3. HandleScope scope;
  4. String::AsciiValue property_name(property);
  5. if(strcmp(*property_name, "createElement"))
  6. cerr << "prop: " << *property_name << endl;
  7. return Handle<Value>();
  8. }
  9.  
  10. // called when a TracedObject is constructed
  11. static Handle<Value> TracedObjectCallback(const Arguments &args)
  12. {
  13. HandleScope scope;
  14. assert(args.Data()->IsFunction());
  15. static Persistent<ObjectTemplate> traced_obj;
  16. if(traced_obj.IsEmpty()) {
  17. traced_obj = Persistent<ObjectTemplate>::New(ObjectTemplate::New());
  18. traced_obj->SetNamedPropertyHandler(TracedGetProperty);
  19. }
  20. Handle<Object> result = traced_obj->NewInstance();
  21. Handle<Function> constructor = Handle<Function>::Cast(args.Data());
  22. vector<Handle<Value> > argvals;
  23. for(int i=0; i < args.Length(); ++i) argvals.push_back(args[i]);
  24. constructor->Call(result, argvals.size(), &argvals[0]);
  25. return scope.Close(result);
  26. }
  27.  
  28. static Handle<Value> TracedObject(const Arguments &args)
  29. {
  30. if(args.Length() != 1 || !args[0]->IsFunction()) return v8::Undefined();
  31. HandleScope scope;
  32. Handle<Function> constructor = Handle<Function>::Cast(args[0]);
  33. Handle<FunctionTemplate> func = FunctionTemplate::New(TracedObjectCallback, constructor);
  34. Handle<Function> result = func->GetFunction();
  35. //result->Set(String::New("prototype"), constructor->Get(String::New("prototype")));
  36. return scope.Close(result);
  37. }
Add Comment
Please, Sign In to add comment