Comment 3 for bug 673385

Revision history for this message
Matthias Gehre (m-gehre) wrote :

I got it fully working with the patch below.

Please note the commented lines inside the 'if'. I expected that
the newClass instruction should push something back on the stack, but running it with those lines uncommented
gives an assert failture sometimes later in incRef. Someone with more knowledge of the codebase may probably easy spot the issue.

The rational behind the change is the following. With Loader.load() an swf is allowed to load another swf as child. Its clearly stated in the documentation that the child's classes will not override the parents classes. This seems to imply that
attempts by the child to register an already known class is not an error condition (it was handled that way before), but should
be ignored.
(Please forgive the uncleanness of the patch)

=== modified file 'scripting/abc_opcodes.cpp'
--- scripting/abc_opcodes.cpp 2011-04-29 20:23:44 +0000
+++ scripting/abc_opcodes.cpp 2011-05-05 23:41:34 +0000
@@ -2361,14 +2361,26 @@

 void ABCVm::newClass(call_context* th, int n)
 {
- LOG(LOG_CALLS, _("newClass ") << n );
+ LOG(LOG_ERROR, _("newClass ") << n );
  method_info* constructor=&th->context->methods[th->context->instances[n].init];
  int name_index=th->context->instances[n].name;
  assert_and_throw(name_index);
  const multiname* mname=th->context->getMultiname(name_index,NULL);

  assert_and_throw(mname->ns.size()==1);
- Class_inherit* ret=new Class_inherit(QName(mname->name_s,mname->ns[0].name));
+ QName qname = QName(mname->name_s,mname->ns[0].name);
+ std::map<QName, Class_base*>::iterator i = sys->classes.find(qname);
+ if(i != sys->classes.end())
+ {
+ LOG(LOG_ERROR,"ABCVm::newClass: Class does already exist");
+ /*th->runtime_stack_pop();
+ Class_base* ret = i->second;
+ ret->incRef();
+ th->runtime_stack_push(ret);*/
+ return;
+ }
+ LOG(LOG_ERROR,"Class_inherit from abc_opcodes");
+ Class_inherit* ret=new Class_inherit(qname);
 #ifdef PROFILING_SUPPORT
  if(!constructor->validProfName)
  {